Sample C Programs

First Simple C program:

#include

main()
{
puts ("Hello World!");
}

------------------------------

C program using if clause:

#include

main()
{
int i=1; /* Defining an integer variable.*/

/*
i == 1 expression is evaluated. If TRUE the
first block is executed.
if i == 1 is FALSE then else block will be executed
*/

if (i == 1)
{
puts ("i is equal to 1\n");
}
else
{
puts("i is NOT equal to 1");
}
}
----------------------------

A Sample program using a while loop:

#include

main()
{
int i=1; /* Defining an integer variable. */

/*
i <= 10 expression is evaluated. If TRUE the
block is executed.
*/

while (i <= 10)
{
printf ("i is %i\n", i);
i++;
}
}

0 comments:

Post a Comment

 
geekarticles.blogspot.com. Powered by Blogger.