View All C Programs

 Previews Example  View All C Programs Next Example 

Program to add and display the sum of two integers entered by user in c

In this program, user is asked to enter two integers. The two integers entered by user will be stored in variables num1 and num2 respectively. This is done using scanf() function. Then, + operator is used for adding variables num1 and num2 and this value is assigned to variable sum.
/*C programming to add and display the sum of two integers entered by user */

#include <stdio.h>
#include <conio.h>
 main( )
{
    int num1, num2, sum;
    printf("Enter two integers: ");
    scanf("%d %d",&num1,&num2); /* Stores the two integer entered by user in variable num1 and num2 */

    sum=num1+num2;      /* Performs addition and stores it in variable sum */
    printf("Sum: %d",sum);  /* Displays sum */
    getch();
}
Result
Enter two integers: 20 10

Sum: 30