Arithmetic operators ใช้คำนวณคณิตศาสตร์พื้นฐาน
ตาราง Operators
| Operator | Description | Example | a=20,b=10 | Output |
|---|---|---|---|---|
| + | Addition | a+b | 20+10 | 30 |
| - | Subtraction | a-b | 20-10 | 10 |
| * | Multiplication | a*b | 20*10 | 200 |
| / | Division | a/b | 20/10 | 2 (quotient) |
| % | Modulo | a%b | 20%10 | 0 (remainder) |
อัลกอริทึม
START
Step 1: ประกาศตัวแปร int
Step 2: รับค่าทุกตัวแปร
Step 3: คำนวณ a+b, a-b, a*b, b/a, a%b
Step 4: พิมพ์ผลลัพธ์
โปรแกรม
#include <stdio.h>
main() {
int a, b;
printf("Enter a, b: ");
scanf("%d %d", &a, &b);
printf("a+b = %d\n", a+b);
printf("a-b = %d\n", a-b);
printf("a*b = %d\n", a*b);
printf("b/a = %d\n", b/a);
printf("a%%b = %d\n", a%b);
}
ผลลัพธ์
Enter a, b: 40 60
a+b = 100
a-b = -20
a*b = 2400
b/a = 1
a%b = 40