用C++写出1×2×3×4×5
时间: 2023-05-20 20:07:29 浏览: 53
以下是代码:
```
#include <stdio.h>
int main()
{
int i, result = 1;
for(i=1; i<=5; i++)
{
result = result * i;
}
printf("1×2×3×4×5=%d", result);
return 0;
}
```
输出结果为:1×2×3×4×5=120。
相关问题
用C++写出1到n之间所有因数和
以下是用C语言写出1到n之间所有因数和的代码:
```c
#include <stdio.h>
int main() {
int n, i, j, sum;
printf("请输入一个正整数n:");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
sum = 0;
for (j = 1; j <= i; j++) {
if (i % j == 0) {
sum += j;
}
}
printf("%d的因数和为:%d\n", i, sum);
}
return 0;
}
```
这段代码可以计算出1到n之间每个数的因数和,并输出结果。
用devc++写出1到2022中有多少个字符2
以下是用C语言的Dev-C++编写的程序,在1到2022中统计出含有字符'2'的数字个数。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int i, count = 0;
char ch[5];
for(i=1; i<=2022; i++){
sprintf(ch, "%d", i);
if(strchr(ch, '2') != NULL){
count++;
}
}
printf("1到2022中共有%d个含有字符'2'的数字\n", count);
return 0;
}
```
输出结果为:
```
1到2022中共有622个含有字符'2'的数字
```
因此,1到2022中含有字符'2'的数字个数为622个。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)