Addition program is one of the simplest program in any programming language. This C program takes two integer numbers from the user and display their sum.
#include<stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: \n");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
return(0);
}
Program Output
Case 1:
Enter two numbers:
-56
28
Sum : -28
Case 2:
Enter two numbers:
125
789
Sum : 914
Program Explanation
1. This program declares three integer variables a,b and sum.
2. Value of variables a and b variables is accepted from the user and their sum is stored in the sum variable.
3. Value of the variable sum is printed using the printf function.
C program to add two numbers - Source code
Program Output
Program Explanation
1. This program declares three integer variables a,b and sum.
2. Value of variables a and b variables is accepted from the user and their sum is stored in the sum variable.
3. Value of the variable sum is printed using the printf function.
need an explanation for this answer? contact us directly to get an explanation for this answer