How to Add Two Numbers in C - Step by Step Examples
How to Add Two Numbers in C ?
Answer
To add two numbers in C, you can use the addition operator (+) between the numbers.
✐ Examples
1 Addition of Two Numbers
In this example,
- We declare two variables
a
andb
to store the numbers we want to add. - We initialize these variables with the desired values.
- We then use the addition operator
+
to add the two numbers and store the result in a variablesum
. - Finally, we print the value of
sum
to display the sum of the two numbers.
C Program
#include <stdio.h>
int main() {
int a = 5, b = 10;
int sum = a + b;
printf("Sum of %d and %d is %d\n", a, b, sum);
return 0;
}
Output
Sum of 5 and 10 is 15
Summary
In this tutorial, we learned How to Add Two Numbers in C language with well detailed examples.