C Program to perform arithmetic operations on integer
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include<stdio.h> main() { int a = 25; int b = 5; printf("%d + %d = %d\n", a ,b, a + b); printf("%d - %d = %d\n", a ,b, a - b); printf("%d * %d = %d\n", a ,b, a * b); printf("%d / %d = %d\n", a ,b, a / b); printf("%d %% %d = %d\n", a ,b, a % b); } |
Output :
1 2 3 4 5 | 25 + 5 = 30 25 - 5 = 20 25 * 5 = 125 25 / 5 = 5 25 % 5 = 0 |
Explanation :
In this example we have performed arithmetic operations in c programming.
Expression | Result |
---|---|
25 + 5 | 30 |
25 - 5 | 20 |
25 * 5 | 125 |
25 / 5 | 5 |
25 % 5 | 0 |
Now see the last line of the program, we used two % symbols
1 | printf("%d %% %d = %d\n", a ,b, a % b); |
There is specific meaning to %d symbol in C programming when we need to print %d as part of string then we need to use two % symbols.