1.求出0~999之间的所有“水仙花数”并输出。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a, b, c;
for (a = 1; a <= 9; ++a)
for (b = 0; b < 10; ++b)
for (c = 0; c < 10; c++)
if (a * 100 + b * 10 + c == a * aa + b * bb + c * c*c)
printf("%d为水仙花数:\n", a * 100 + b * 10 + c);
system(“pause”);
return 0;
}
2.求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和,其中a是一个数字,
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main()
{
int num = 0;
int count = 0;
int sum = 0;
int tmp = 0;
printf(“请输入num和count\n”);
scanf("%d%d", &num, &count);
int i = 0;
for (i = 0; i < count; i++)
{
tmp = tmp * 10 + num;
sum += tmp;
}
printf("%d\n", sum);
system(“pause”);
return 0;
}
3.在屏幕上输出以下图案:
*
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i = 0, j = 0;
for (i = 1; i <= 7; i++)
{
for (j = 1; j <= 2 * i - 1; j++)
{
printf("");
}
printf("\n");
}
for (i = 8; i <= 13; i++)
{
for (j = 1; j <= 27 - 2 * i; j++)
{
printf("");
}
printf("\n");
}
system(“pause”);
return 0;
}