Arithmetic operators are used to perform arithmetic operations like addition, subtraction, multiplication, division and modulo.
Operator | Operation |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulo |
Example C program using arithmetic operators:
#include <stdio.h> int main() { int ch, input1, input2, res; do { printf("Menu:\n"); printf("1. Addition\n2. Subtraction\n"); printf("3. Multiplication\n3. Division\n"); printf("4. Modulo\n"); printf("Enter your choice:"); scanf("%d", &ch); printf("Enter your input1 and input2\n"); scanf("%d%d", &input1, &input2); switch (ch) { case 1: res = input1 + input2; break; case 2: res = input1 - input2; break; case 3: res = input1 * input2; break; case 4: res = input1 / input2; break; case 5: res = input1 % input2; break; default: printf("You have entered wrong option\n"); break; } printf("Result: %d\n", res); printf("Do you want to continue(0/1):"); scanf("%d", &ch); } while (ch == 1); return 0; }
Output:
jp@jp-VirtualBox:~/$ ./a.out
Menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulo
Enter your choice:1
Enter your input1 and input2
10324 8987
Result: 19311
Do you want to continue(0/1):1
Menu:
1. Addition
2. Subtraction
3. Multiplication
3. Division
4. Modulo
Enter your choice:4
Enter your input1 and input2
101 100
Result: 1
Do you want to continue(0/1):0
Menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulo
Enter your choice:1
Enter your input1 and input2
10324 8987
Result: 19311
Do you want to continue(0/1):1
Menu:
1. Addition
2. Subtraction
3. Multiplication
3. Division
4. Modulo
Enter your choice:4
Enter your input1 and input2
101 100
Result: 1
Do you want to continue(0/1):0
Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051
ReplyDeleteNice and very helpful article keep posting helpful C programming examples...
ReplyDeleteI have writes my first C program in 1st year of my college