in , ,

C Program to Add Two Integers 

C Program to Add Two Integers 
C Program to Add Two Integers 

C Program to Add Two Integers:

In this example, the user is asked to enter two integers. Then, the sum of these two integers is calculated and shown on the screen.

To understand this example, you should have knowledge of the following C programming topics:

C Data Types

C Variables, Constants, and Literals

C Input-Output (I/O)

C Programming Operators


Program to Add Two Integers

#include <stdio.h>
int main() {    

    int number1, number2, sum;
    
    printf("Enter two integers: ");
    scanf("%d %d", &number1, &number2);

    // calculating sum
    sum = number1 + number2;      
    
    printf("%d + %d = %d", number1, number2, sum);
    return 0;
}

Output

Enter two integers: 12
11
12 + 11 = 23

In this program, the user is asked to enter two integers. These two integers are stored in variables number1 and number2 respectively.

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

Then, these two numbers are added using the + operator, and the result is stored in the sum variable.

sum = number1 + number2;

C-Program-to-Print-Elements-in-an-Array
Finally, the printf() function is used to display the sum of numbers.
printf("%d + %d = %d", number1, number2, sum);

Please feel free to give your comment if you face any difficulty here.

For more Articles click on the below link.

salman khan

Written by worldofitech

Leave a Reply

C Program to Print an Integer (Entered by the User)

C Program to Print an Integer (Entered by the User)

C Program to Multiply Two Floating-Point Numbers

C Program to Multiply Two Floating-Point Numbers