C Program to Add two Numbers
In C programming language you will know how to add two numbers in c language with examples, you need use Integer data type to perform addition task lets us understand adding two number in C .
#include<stdio.h>
void main()
{
int number1, number2, sum;
printf(” Enter first Number = “);
scanf(“%d”,&number1);
printf(” Enter second Number = “);
scanf(“%d”,&number2);
sum=number1+number2;
printf( “%d + %d = %d”,number1,number2, sum);
}
Output
Enter first Number = 10
Enter Second Number = 25
10+25 = 35
Note
#include<stdio.h>
This is pre processor header file which includes printf function to print output on screen and scanf function to take user input from keyboard .
void main()
This is main function from where c program execution starts and void have nothing to return the main in this program.
int number1, number2, sum;
These are integer data type variables number1 will store first value and number2 store second value
sum will be used to store total of two numbers
printf(” Enter first Number = “);
Message on computer screen to enter first number
scanf(“%d”,&number1);
This statement will take number1 from user and store at this address &number1
printf(” Enter second Number = “);
Message on computer screen to enter second number
scanf(“%d”,&number2);
This statement will take number2 from user and store at this address &number2
sum=number1+number2;
Add two number in c formula
printf( “%d + %d = %d”,number1,number2, sum);
This statement will print sum of two numbers
Add two numbers in C Programming
Second Example
#include<stdio.h>
int main()
{
int number1=15, number2=10, sum;
sum = number1+number2;
printf( “%d + %d = %d”,number1, number2, sum);
return 0;
}
Add two numbers in C