C – Calculate Sum of Two Integers
This is a simple C program to take the input of two integer numbers from the user and calculate the sum of both integers and pint on screen.
C Program to Add Two Integers
Create a new file using the below content. This script will ask to enter two integer values and calculate the sum of both numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<stdio.h> int main() { //Define varaibles int i, j, sum; //Take user input printf("Enter 1'st integer:"); scanf("%d", &i); printf("Enter 2'nd integer:"); scanf("%d", &j); //Calculate sum of integers sum = i + j; //Print sum of integers printf("Sum is: %d\n", sum); return 0; } |
Run above program. Output:
Enter 1'st number:10 Enter 2'nd number:20 Sum is: 30