Q:

C program to add two integer numbers

belongs to collection: C programs - Basic C Programs

0

Write C program takes two integer numbers from the user and print their sum on the screen.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C program to add two integer numbers - Source code

 #include<stdio.h>
 
int main() {
   int a, b, sum;
 
   printf("\nEnter the two numbers: ");
   scanf("%d %d", &a, &b);
 
   sum = a + b;
 
   printf("Sum of %d and %d is %d", a,b,sum);
 
   return(0);
}

Program Output

Case 1:

Enter the two numbers: 456
26
Sum of 456 and 26 is 482

Case 2:

Enter the two numbers: 721
457
Sum of 721 and 457 is 1178

Program Explanation

1. Three integers variables a, b and sum are declared.

2. User is asked to input two integers to calculate the sum. Entered numbers are stored in a and b variables using the scanf function.

3. Sum of a and b is obtained using arithmetic Addition(+) operator. 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to multiply two floating point numbers... >>
<< C program to find average of three numbers...