C语音for语句编写2的10次方
时间: 2023-05-20 13:04:55 浏览: 77
的代码怎么写?
以下是代码示例:
```c
#include <stdio.h>
int main() {
int result = 1;
for (int i = 0; i < 10; i++) {
result *= 2;
}
printf("2的10次方是:%d", result);
return 0;
}
```
输出结果为:2的10次方是:1024
相关问题
用while语句编写一个2的10次方的程序
以下是用 while 语句编写的计算 2 的 10 次方的程序:
```
#include <stdio.h>
int main() {
int base = 2;
int exponent = 10;
int result = 1;
while (exponent > 0) {
result *= base;
exponent--;
}
printf("2 的 10 次方是:%d\n", result);
return 0;
}
```
输出结果为:
```
2 的 10 次方是:1024
```
c语言,for语句编写程序,输出所有的水仙花数
以下是C语言的for循环程序,用于输出所有的水仙花数:
```c
#include <stdio.h>
int main() {
int i, j, k, n;
for (n = 100; n < 1000; n++) {
i = n / 100;
j = (n / 10) % 10;
k = n % 10;
if (i * i * i + j * j * j + k * k * k == n) {
printf("%d ", n);
}
}
return 0;
}
```
这个程序会输出所有的三位数水仙花数,即153、370、371和407。