Write a program in C Programming to perform basic arithmetic operation like addition, subtraction, multiplication and division. C Programming Language comes with arithmetic operators. Operator we will use in the C Program are:

- ‘+’ Addition
- ‘-‘ Subtraction
- ‘*’ Multiplication
- ‘/’ Division

This operation can be performed on Integer, Float or Double Number. These are **Data Types.**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/** Write a C program to perform arithmetic Operation on two Numbers **/ #include <stdio.h> int main() { int first, second, add, subtract, multiply; float divide; printf("Enter two integers\n"); scanf("%d%d", &first, &second); add = first + second; subtract = first - second; multiply = first * second; divide = first / (float)second; //typecasting printf("Sum = %d\n",add); printf("Difference = %d\n",subtract); printf("Multiplication = %d\n",multiply); printf("Division = %.2f\n",divide); return 0; } |

Output:

1 2 3 4 5 6 |
Enter Two Integers 5 4 Sum = 9 Difference = 1 Multiplication = 20 Division = 1.25 |

In c language when we divide two integers we get integer result for example 5/2 evaluates to 2. As a general rule integer/integer = integer and float/integer = float or integer/float = float. So we convert denominator to float in our program, you may also write float in numerator. This explicit conversion is known as **typecasting**.