Tuesday, December 23, 2014

Fantastic C programs



1.  Program

#include
#include
void main ()
{

int a, b;
int c;
float f;
  a = 10;
  b = 20;
 
  c = a + b;
  printf("value of c : %d \n", c);

  f = 70.0/3.0;
  printf("value of f : %f \n", f);

  return 0;
  getch();
}

Output
value of c : 30
value of f : 23.333334
 
2. Program
#include 
#include 
#define length 10   
#define width  5
#define newline '\n'
 
void main()
{
 
   int area;  
  
   area = length * width;
   printf("value of area : %d", area);
   printf("%c", newline);
 
   return 0;
   getch();
}

Output
               value of area : 50
 
3. Program
#include 
#include 
void func(void);
 
static int count = 5; 
 
void main()
{
   while(count--)
   {
      func();
   }
   return 0;
}
void func( void )
{
   static int i = 5; 
   i++;
 
   printf("i is %d and count is %d\n", i, count);
   getch();
}

Output
i is 6 and count is 4
i is 7 and count is 3
i is 8 and count is 2
i is 9 and count is 1
i is 10 and count is 0
 

No comments:

Post a Comment