C programs

C Program for Addition of two Numbers

Here is a simple program of addition of two numbers. In this program input taken dynamically from user and perform addition of two number and show result to user. To perform addition need to use arithmetic operator  +.




void main()


int a,b,c;//variable declaration


printf("enter first number:\t");// Accept first number

scanf("%d",&a); // address of first number

printf("enter second number:\t");// Accept second num

scanf("%d",&b); // address of second number

c=a+b; // add two numbers

printf("answer=%d\n",c); // print result



When Run The Program Following Output:

enter first number:   10

enter second number:  20



In above program input taken from user at run time using scanf()

Perform addition using the statement c=a+b; result is saved in variable c

To print addition result printf("ans=%d\n",c);    is used.

The // symbol used to give comments in program to understand the code to human, That does not effect on program it is only for user to understand program.

Releted Programs

© 2017 codewmAll rights reserved.