Saturday, July 23, 2011

C Program to print various STAR PATTERNS II









       

       (6)

#include <stdio.h> 
int main() 
{   
    char prnt = '*';
     int i, j, k, s, nos = -1;
     for (i = 5; i >= 1; i--)
     {  
                 for (j = 1; j <= i; j++)     
               { 
                                       printf("%2c", prnt);
               } 
                for (s = nos; s >= 1; s--) 
               {   
                     printf("  ");  
                } 
               for (k = 1; k <= i; k++)
              {   if (i == 5 && k == 5) 
                  {    continue;  
                  }   
                   printf("%2c", prnt);  
               }  
             nos = nos + 2;
             printf("\n"); 
           }
               nos = 5; 
      for (i = 2; i <= 5; i++) 
     { 
          for (j = 1; j <= i; j++) 
         {
               printf("%2c", prnt);
         }
          for (s = nos; s >= 1; s--) 
        { 
                   printf("  "); 
        }
         for (k = 1; k <= i; k++)
       {   
           if (i == 5 && k == 5) 
          {    break;  
          }
          printf("%2c", prnt); 
       }  
             nos = nos - 2;  
          printf("\n"); 
  } 
      return 0;
}















                 (7)


#include <stdio.h> 
int main() 

     char prnt = '*'; 
     int i, j, k, s, nos = -1;
     for (i = 5; i >= 1; i--) 
    { 
         for (j = 1; j <= i; j++) 
         { 
            printf("%2c", prnt);
         }
         for (s = nos; s >= 1; s--) 
         {   
            printf("  ");  
         }  
         for (k = 1; k <= i; k++) 
         {   
            if (i == 5 && k == 5) 
            {    
               continue; 
            } 
            printf("%2c", prnt);  
         } 
            nos = nos + 2; 
            printf("\n"); 
    } 
       nos = 5;
      for (i = 2; i <= 5; i++) 
      {  
         for (j = 1; j <= i; j++) 
         {
             printf("%2c", prnt);
         }
      for (s = nos; s >= 1; s--)
      {   
         printf("  "); 
      }  
      for (k = 1; k <= i; k++) 
      {  
           if (i == 5 && k == 5)
           {   
              break;  
           }   
          printf("%2c", prnt);  
      } 
          nos = nos - 2;  
          printf("\n"); 
  } 
      return 0;
}













         


                         (8)


#include <stdio.h>
int main() 

       char prnt = '*'; 
       int i, j, k, s, sp, nos = 0, nosp = -1; 
       for (i = 9; i >= 3; (i = i - 2)) 
       {  
          for (s = nos; s >= 1; s--)
          {  
             printf("  "); 
          }  
          for (j = 1; j <= i; j++) 
          {
             printf("%2c", prnt);
          }
          for (sp = nosp; sp >= 1; sp--) 
          {   
             printf("  ");  
          }  
          for (k = 1; k <= i; k++) 
          { 
            if (i == 9 && k == 1)
            {
               continue;
            }
            printf("%2c", prnt);
          }
              nos++;
              nosp = nosp + 2;
              printf("\n");
              nos = 4;
       for (i = 9; i >= 1; (i = i - 2)) 
       { 
           for (s = nos; s >= 1; s--) 
           {  
               printf("  ");  
           } 
           for (j = 1; j <= i; j++)
           {   
               printf("%2c", prnt); 
           } 
               nos++; 
               printf("\n");
       }  
return 0;
}


















   

       
              (9)


#include <stdio.h>
/* * nos = Num. of spaces required in the triangle. * i   = Counter for the num. of 


charcters to print in each row * skip= A flag for checking whether to *       skip a 


character in a row. * */


int triangle(int nos, int i, int skip)

     char prnt = '*'; 
     int s, j;
     for (s = nos; s >= 1; s--) 
     {  
         printf("  "); 
     } 
     for (j = 1; j <= i; j++)
     { 
        if (skip != 0) 
        {   
           if (i == 4 && j == 1) 
           {    continue;   
           }  
        } 
        printf("%2c", prnt);
     } 
      return 0;

int main() 

     int i, nos = 4;
     for (i = 1; i <= 7; (i = i + 2)) 
     {  
          triangle(nos, i, 0);  
          nos--;  
          printf("\n");
     } 
      nos = 5; 
     for (i = 1; i <= 4; i++) 
     {
        triangle(1, i, 0); //one space needed in each case of the formation
        triangle(nos, i, 1); //skip printing one star in the last row.
        nos = nos - 2;
        printf("\n");
     }
      nos = 1;
     for (i = 3; i >= 1; i--)
     {  
        triangle(1, i, 0); 
        triangle(nos, i, 0);  
        nos = nos + 2; 
        printf("\n"); 
     } 
        nos = 1;
     for (i = 7; i >= 1; (i = i - 2)) 
     {  
        triangle(nos, i, 0);  
        nos++;  
        printf("\n"); 
     } 
     return 0;
}











                               


                                       (10)



#include <stdio.h>
/* * nos = Num. of spaces required in the triangle. * i   = Counter for the num. of 


charcters to print in each row * skip= A flag for checking whether to *       skip a 


character in a row. * */


int triangle(int nos, int i, int skip)

     char prnt = '*'; 
     int s, j;
     for (s = nos; s >= 1; s--) 
     {  
         printf("  "); 
     } 
     for (j = 1; j <= i; j++)
     { 
        if (skip != 0) 
        {   
           if (i == 4 && j == 1) 
           {    continue;   
           }  
        } 
        printf("%2c", prnt);
     } 
      return 0;

int main() 

     int i, nos = 4;
     for (i = 1; i <= 7; (i = i + 2)) 
     {  
          triangle(nos, i, 0);  
          nos--;  
          printf("\n");
     } 
      nos = 5; 
     for (i = 1; i <= 4; i++) 
     {
        triangle(1, i, 0); //one space needed in each case of the formation
        triangle(nos, i, 1); //skip printing one star in the last row.
        nos = nos - 2;
        printf("\n");
     }
      nos = 1;
     for (i = 3; i >= 1; i--)
     {  
        triangle(1, i, 0); 
        triangle(nos, i, 0);  
        nos = nos + 2; 
        printf("\n"); 
     } 
        nos = 1;
     for (i = 7; i >= 1; (i = i - 2)) 
     {  
        triangle(nos, i, 0);  
        nos++;  
        printf("\n"); 
     } 
     return 0;
}





//  This post is inspired by the great response to its first part.........................    
//   I hope the viewers will like these patterns again as they did for the previous post......
//  Please let me know if any errors are encountered........


Friday, July 22, 2011

C Progarm to calculate Electric Bill



#include<stdio.h>
#include<conio.h>
void main()
{
   int cno,pmr,cmr,cu;
   float total;
   char sec;
   char cname[10];
   clrscr();
   printf(" ENTER the SECTOR     : ");
   scanf("%c",&sec);
   printf(" Enter customer name   : ");
   scanf("%s",&cname);
   printf(" Enter customer number  :     ");
   scanf("%d",cno);
   printf(" Enter the previous units  : ");
   scanf("%d",&pmr);
   printf(" Enter the current units  : ");
   scanf("%d",&cmr);
   cu=cmr-pmr;
   if(sec == 'a')
   {
      if(cu>300)
      total=cu*2.00;
if(cu>200  && cu<=300)
total=cu*1.50;
 if(cu>100 && cu<=200)
 total=cu*1.00;
   if(cu<=100)
   total=cu*0.50;
   }
   if(sec=='i')
   {
      if(cu>300)
      total=cu*4.00;
if(cu>200  && cu<=300)
total=cu*3.00;
if(cu>100 && cu<=200)
 total=cu*2.00;
   if(cu<=100)
   total=cu*1.00;
   }
    if(sec == 'a')
   {
      if(cu>300)
      total=cu*2.00;
if(cu>200  && cu<=300)
total=cu*1.50;
 if(cu>100 && cu<=200)
 total=cu*1.00;
   if(cu<=100)
   total=cu*0.50;
   }
    if(sec == 'd')
   {
      if(cu>300)
      total=cu*2.00;
if(cu>200  && cu<=300)
total=cu*1.50;
 if(cu>100 && cu<=200)
 total=cu*1.00;
   if(cu<=100)
   total=cu*0.50;
   }
   printf("\n Customer name   :   %s ",cname);
   printf("\n Customer number :   %d",cno);
   printf("\n Previous Units  :   %d",pmr);
   printf("\n Current Units   :   %d",cmr);
   printf("\n Category        :   %c",sec);
   printf("\n Consumed Units  :   %d",cu);
   printf("\n Electric Bill   :   %f",total);
   getch();
   }











Wednesday, July 6, 2011

C Progran to illustrate the use Of Macros

#include<stdio.h>
#define ISLOWER(c) (c>=97&&c<=122)
#define ISUPPER(c) (c>=65&&c<=90)
#define ISALPHA(c) ISLOWER(c) || ISUPPER(c)

int main()

{
char chr;

printf("Enter a character:\n");

scanf("%c",&chr);

if (ISALPHA(chr) )

{
printf("%c is an alphabetical character.\n",chr);
}
else
{
printf("%c is not an alphabetical character.\n",chr);
}

return 0;

}