数字和操作 ()
numbers , and operations with ()
所以我在 C 中的运算符逻辑上遇到了问题。不知道编译器怎么把运行那些(%)/?
#include <stdio.h>
int main (){
int number1=1606,number2,number3,number4;
number2 = number1/5000;
number3 = (number1%5000)/1000;
number4 = (number1%5000)%1000/100;
printf("%d\n%d\n%d\n%d",number1,number2,number3,number4);
return 0;
}
所以我不明白数字 3?
不是 1606%5000 = 3212 然后 / 1000 = 3 吗?所以我从中得到 1 它是如何工作的?
在此声明中
number3 = (number1%5000)/1000;
使用了整数运算。运算符 % 产生运算 /.
的余数
所以子表达式 number1%5000
给出值 1606
因为
number1 可以表示为
number1 = 0 * 5000 + 1606.
将余数除以 1000
得到 1
。
来自 C 标准(6.5.5 乘法运算符)
5 The result of the / operator is the quotient from the division of
the first operand by the second; the result of the % operator is the
remainder. In both operations, if the value of the second operand is
zero, the behavior is undefined.
所以我在 C 中的运算符逻辑上遇到了问题。不知道编译器怎么把运行那些(%)/?
#include <stdio.h>
int main (){
int number1=1606,number2,number3,number4;
number2 = number1/5000;
number3 = (number1%5000)/1000;
number4 = (number1%5000)%1000/100;
printf("%d\n%d\n%d\n%d",number1,number2,number3,number4);
return 0;
}
所以我不明白数字 3? 不是 1606%5000 = 3212 然后 / 1000 = 3 吗?所以我从中得到 1 它是如何工作的?
在此声明中
number3 = (number1%5000)/1000;
使用了整数运算。运算符 % 产生运算 /.
的余数所以子表达式 number1%5000
给出值 1606
因为
number1 可以表示为
number1 = 0 * 5000 + 1606.
将余数除以 1000
得到 1
。
来自 C 标准(6.5.5 乘法运算符)
5 The result of the / operator is the quotient from the division of the first operand by the second; the result of the % operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined.