The road to advanced C language: How to solve the problems of addition, subtraction, multiplication and division of any two numbers

Tip: You can refer to the code written by the blogger in his previous article to find ideas.

Article directory

  • think for a while
  • 1. Tips
  • 2. Write the addition, subtraction, multiplication and division codes for any two integers based on the sum of any two integers.
    • 1Easy to write
    • 2. The author’s suggestion
  • Summarize


think for a while:

提示:建议读者先进行自我思考,通过对博客的对比,不断挖掘自生潜力

How to add, subtract, multiply and divide any two integers ? How do you assign multiple letters to them? Or just two letters?

Readers are advised to think first.

Integers can be written according to the author's code, but can any two or more decimals also be used? I hope everyone can think about it or learn from the content of the author’s next blog.


提示:以下是本篇文章正文内容,下面案例可供参考

1. How to code the sum of any two integers?

For addition, subtraction, multiplication and division of any two integers , can we refer to the code for summing any two integers?

2. Simply write code

The article is for reference only

A simple code for addition, subtraction, multiplication and division of any two integers is as follows (example):

The simplest code program is as shown in the figure, but the author does not recommend writing it this way, because looking at the results after operation, you cannot clearly see which is the addition, subtraction, multiplication and division of x and y, and you have to analyze it yourself.

//对于任意两个整数求加减乘除运算
#include <stdio.h。
int main ()
{
int x,y;
printf("请输入任意两个整数:  \n")
scanf("%d,%d"&x,&y);
printf("任意两个整数的和为:%d\n",x+y);
printf("任意两个整数的差为:%d\n",x-y);
printf("任意两个整数的乘积为:%d\n",x*y);
printf("任意两个整数的商为:%d\n",x/y);    //这里的商表示的为:求出的整数部分,至于余数,则不在考虑之列
return 0;
}

 The author particularly recommends this kind of code. The comments can help you know the purpose of the code, and the results after operation are still clear and eye-catching.

The important code is as follows (example):

scanf("%d,%d"&x,&y);
printf("任意两个整数的和为:%d\n",x+y);
printf("任意两个整数的差为:%d\n",x-y);
printf("任意两个整数的乘积为:%d\n",x*y);
printf("任意两个整数的商为:%d\n",x/y);

The code here is particularly important. Assign: x+y to %d, and then output the result of %d. Similar derivation can be made for the other three operators. In this code, of course the author is different and the code written is different, but the overall output result is the same.


Summarize

Here is a summary of the article:
: The above is what I will talk about today. This article only briefly introduces the addition, subtraction, multiplication and division operations of any two integers . However, for the addition, subtraction, multiplication and division of any two decimals, it is recommended that readers think carefully about it themselves. If you have any questions, please refer to the author's next blog for details.

Guess you like

Origin blog.csdn.net/weixin_64308540/article/details/124642970#comments_26737831