Table of Contents
C program to Add Two Integers Entered by the User
#include<stdio.h>
int main()
{
int result,var1,var2;
printf("Enter the values for var1 and var2 \n");
scanf("%d %d",&var1,&var2);
result=var1+var2;//calculating sum
printf("The result is %d \n",result);
return 0;
}
Output
Code Explanation
First, declare two integer variables to store the user inputted values. Then using printf() function print “Enter the values for var1 and var2”. After that read the input values entered by the user using scanf(). These 2 values are stored in var1 and var2 respectively. Those two values are added using the ‘+’ operator. The result will be stored in variable result. This result will be displayed on the console using print().
People also Ask
Which function is used to add two numbers?
The addition() function takes two arguments and calculates its sum. Then it returns the value to the main function.