Showing posts with label simlpe c. Show all posts
Showing posts with label simlpe c. Show all posts

Wednesday, February 10, 2010

simple c program for if condition within do while

#include
#include

int main()
{
int index;

   index = 1;
   do
   {
      printf("The count is now %2d",index);
      if (index == 3)
         printf(" and is equal to three.");
      if (index == 7)
         printf(" and is equal to seven.");
      printf("\n");
      index = index + 1;
   } while (index < 11);
 getch();
   return 0;
}



/* Result of execution

The count is now  1
The count is now  2
The count is now  3 and is equal to three.
The count is now  4
The count is now  5
The count is now  6
The count is now  7 and is equal to seven.
The count is now  8
The count is now  9
The count is now  10

*/

simple c program in do while

#include
#include

int main()
{
int index;

   index = 0;
   do
   {
      printf("c is simple\n");
      index = index + 1;
   } while (index < 10);

getch();  
return 0;
}



/* Result of execution

c is simple
c is simple
c is simple
c is simple
c is simple
c is simple
c is simple
c is simple
c is simple
c is simple


*/

simple c program in while loop

#include
#include

int main()
{
int index;

   index = 0;
   while (index < 10)
   {
      printf("S.GUNA\n");
      index = index + 1;
   }
  getch();
   return 0;
}



/* Result of execution

S.GUNA
S.GUNA
S.GUNA
S.GUNA
S.GUNA
S.GUNA
S.GUNA
S.GUNA
S.GUNA
S.GUNA

simple c program for local variable

#include
#include
int main()
{
int index;

 index = 13;
  printf("The value of the index is %d\n", index);
   index = 27;
   printf("The value of the index is %d\n", index);
   index = 10;
   printf("The value of the index is %d\n", index);
getch();
   return 0;
}