Adding Two Integers In A C Program

Write a C program that can calculate and display the sum of two integers

Click here to view the solution!
#include <stdio.h>
int main() {

   int number1, number2, sum;

   print("Enter two integers: ");
   scanf("%d%d", &number1, &number2);

   // calculating sum
   sum = number1 + number2;
 
   printf("%d + %d", number1, number2, sum);
   return 0;
} 
Click here to view the output!
Enter two integers: 65, 12
65 + 12 = 77
Click here to view the explanation!

We first declare our integer variables (number 1 & number 2) then use the first printf( ) function to prompt the users for the two integers, which are scanned and stored in our variables (number 1) and (number 2).

We then use the sum operator (+) to add the number variables and then store it in the (sum) variable. Finally, we use the printf() function to display the result on the screen.

%d bloggers like this: