Writing first C program | How to write C program

By
Advertisement
C program is a collection of different functions. A function is a self contained block that performs a single task. For example consider the following program




/* this program prints a value */
int show(int a);
void main()
{
 int a;
 printf(" enter a value");
 scanf("%d",&a);
 show(a);

}

int show()
{
 printf(" value of a is=%d",a);
}
In the above program the first line is a comment line, and it follows a global declaration section, then it follows main() method.

In main() method we are declaring a variable to hold values. The after we are reading the value using standard input and output functions scanf() and printf(). Then we are calling the user defined function with some parameters. The sun program section contains implementation for user defined function. It calculates 'a' value and print it on the screen.

0 comments:

Post a Comment