1+22+333+……的C语言代码
时间: 2023-10-07 08:04:21 浏览: 109
以下是输出1 22 333 ……的C语言代码:
```c
#include <stdio.h>
int main() {
int n = 10; // 输出前10个数
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
printf("%d", i); // 输出i
}
printf(" "); // 输出空格
}
return 0;
}
```
输出结果为:
```
1 22 333 4444 55555 666666 7777777 88888888 999999999 10101010101010101010
```
相关问题
使用函数实现求下列值++1!+1!+2!+1!+2!+3!+……+1!+2!+3!+……+n!用C语言
以下是使用函数实现求下列值1!+2!+3!+4!+…+10!的C语言代码:
```c
#include <stdio.h>
#include <stdlib.h>
int Factor(int n) //计算n的阶乘
{
int result = 1;
for (int i = 1; i <= n; i += 1) {
result *= i;
}
return result;
}
int FactorSum(int n) //计算1!+2!+3!+...+n!
{
int sum = 0;
for (int i = 1; i <= n; i += 1) {
sum += Factor(i);
}
return sum;
}
int main()
{
int n = 10;
int result = FactorSum(n);
printf("1!+2!+3!+...+%d! = %d\n", n, result);
system("pause");
return 0;
}
```
使用函数实现求下列值 1!+1!+2!+1!+2!+3!+……+1!+2!+3!+……+n!用C语言
以下是使用函数实现求下列值1!+1!+2!+1!+2!+3!+……+1!+2!+3!+……+n!的C语言代码:
```c
#include <stdio.h>
#include <stdlib.h>
int Factor(int n) //计算n的阶乘
{
int result = 1;
for (int i = 1; i <= n; i += 1) {
result *= i;
}
return result;
}
int FactorSum(int n) //计算1!+2!+3!+...+n!
{
int sum = 0;
for (int i = 1; i <= n; i += 1) {
for (int j = 1; j <= i; j += 1) {
sum += Factor(j);
}
}
return sum;
}
int main() {
int n = 5; //n为5
int result = FactorSum(n);
printf("result = %d\n", result); //输出结果
system("pause");
return 0;
}
```
阅读全文