C programming 加、减、乘、除以及求余数

版权声明:转载请附上博客地址 https://blog.csdn.net/weixin_38134491/article/details/84678307

本节主要考察几个知识点:

  • 用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;
}





猜你喜欢

转载自blog.csdn.net/weixin_38134491/article/details/84678307
今日推荐