C语言a=1000%999多少
时间: 2023-10-02 11:09:58 浏览: 100
在 C 语言中,%是求模运算符,其作用是求两个数相除的余数。因此,表达式 `a = 1000 % 999` 的值可以通过计算 1000 除以 999 的余数来得到。
具体计算过程如下:
1. 计算 1000 ÷ 999 的商数,商数为 1,余数为 1。
2. 因此,表达式 `a = 1000 % 999` 的值为 1。
因此,变量 `a` 的值为 1。
相关问题
C语言打印输出水仙花数
以下是C语言打印输出水仙花数的代码:
```c
#include <stdio.h>
#include <stdlib.h>
int main(){
int a = 0; //百位
int b = 0; //十位
int c = 0; //个位
for(int i = 100; i < 1000; i++){
a = i / 100;
b = i / 10 % 10;
c = i % 10;
if(i == a*a*a + b*b*b + c*c*c){
printf("%d\n", i);
}
}
return 0;
}
```
该程序使用for循环遍历100到999之间的所有三位数,然后将其百位、十位和个位分别计算出来。接着,使用if语句判断该数是否为水仙花数,如果是,则输出该数。
c语言输出100-999中所有的“水仙花数”,所谓“水仙花数”是指一个3位数,其各位数字立方和等于该数本身的流程图
以下是C语言输出100-999中所有的“水仙花数”的流程图:
```flow
st=>start: 开始
op1=>operation: 从100到999循环
op2=>operation: 取出当前数的百位、十位、个位
op3=>operation: 计算当前数的各位数字立方和
cond=>condition: 判断各位数字立方和是否等于当前数
op4=>operation: 输出当前数
e=>end: 结束
st->op1->op2->op3->cond
cond(yes)->op4->op1
cond(no)->op1
```
C语言代码如下:
```c
#include <stdio.h>
#include <math.h>
int main() {
int i, j, k, num;
for (int a = 100; a < 1000; a++) {
i = a / 100;
j = a % 100 / 10;
k = a % 100 % 10;
num = pow(i, 3) + pow(j, 3) + pow(k, 3);
if (num == a) {
printf("%d\n", a);
}
}
return 0;
}
```