#include<stdio.h> void main() { int a, b, c; pritnf("Please enter first value:"); //Accepting the first value from keyboard scanf("%d",&a); pritnf("Please enter second value:"); //Accepting the second value from keyboard scanf("%d",&b); //Adding two numbers c=a+b; //Printing the output pritnf("%d+%d=%d",a,b,c); }
Please enter first value: 10 Please enter second value: 20 10+20=30
Explanation
- Each and every C program execution starts with
main
function. The first statement in ourmain
function declares three variables called a, b, c - 3 memory locations are created with the a, b, c variable declaration. a and b will hold the value entered at the run time and c holds the result of the addition
printf
statemtn prints the information on the standard console device (i.e.; monitor)scanf
statement waits for user input from the standard input device (i.e.; keyboard) and when the value is entered, it will be pushed to the corresponding variable+
operator adds two operands and returns the result=
operator assigns the value to the variable