C programming 加、減、乘、除以及求餘數
阿新 • • 發佈:2018-12-04
本節主要考察幾個知識點:
- 用C語言求實現數學求和
- 求乘積
- 差
- 商
- 求餘數
Problem:
Write a program that asks the user to enter two numbers, obtains them from the user and prints their
(1) sum, (2) product, (3) difference, (4) quotient, and (5) remainder
Console result as follows:
Enter two numbers: 20 5
The sum is 25
The product is 100
The difference is 15
The quotient is 4
The remainder is 0
#include<stdio.h> #include<stdlib.h> int main(void) { int a, b; printf("Enter two numbers:"); scanf_s("%d %d", &a, &b); printf("The sum is %d\n", a*b); printf("The product is %d\n", a + b); printf("The difference is %d\n", a-b); printf("The quotient is %d\n", a/b); printf("The remainder is %d\n", a%b); system("pause"); return 0; }