考试

第一题
include<stdio.h>
int main()
{
int i, j, sum, all;
all = 0;
for (i = 1; i <= 50; i++)
{
sum = 0;
for (j = 1; j <= i; j++)
{
sum += j;
} //计算1加到i的和
all += sum; //计算50个sum的和
}
printf("all = %d", all);
return 0;
}
第二题
include<stdio.h>
int main()
{
int n = 1, i = 1, x = 0, line, k;
char ch = 'A';
scanf("%d", &line);//输入上金字塔的行数
for (ch = 'A'; ch - 'A' <= line - 1; ch++)
{
for (k = line - i; k >= 0; k--)
{
printf(" ");//输出空格
}
printf("%c", ch);//输出字母
for (x = 1; x <= 2 * i - 3; x++)
{
printf(" ");//输出空格
}
if (ch != 'A')
printf("%c", ch);//输出字母
printf("\n");//换行
i++;
}//输出上金字塔
i = 1;
ch = ch - 2;
for (ch; ch - 'A' >= 0; ch--)
{
for (k = 1; k <= i + 1; k++)
{
printf(" ");//输出空格
}
printf("%c", ch);//输出字母
for (x = (ch - 'A' - 1) * 2; x >= 0; x = x - 1)
{
printf(" ");//输出空格
}
if (ch != 'A')
printf("%c", ch);//输出字母
printf("\n");//换行
i++;
}
return 0;
}
第三题
include<stdio.h>
int main()
{
int a, b, c, d, i = 0;
for (a = 0; a <= 9; a++)
{
for (b = 0; b <= 9; b++)
{
for (c = 0; c <= 9; c++)
{
for (d = 0; d <= 9; d++)
{
if ((a * 10 + b) * (c * 10 + d) == (b * 10 + a) * (d * 10 + c))
{
printf("%d%d * %d%d = %d%d * %d%d ", a, b, c, d, b, a, d, c);
i++;
if (i % 3 == 0)//每三个式子换一行
printf("\n");
}
}
}
}
}
return 0;
}
第四题
include<stdio.h>

include<time.h>

include<stdlib.h>

int main()
{
int a, b;
srand(time(0));//产生随机种子
a = rand();
b = rand();//随机生成a,b
for (int i = 2; i <= 100; i++)
{
if (a >= b)
a = rand();
else
b = a;//用随机数代替较大值
}
printf("%d", b);//输出最小值
return 0;
}

posted @ 2020-11-22 23:29  山木L  阅读(84)  评论(0)    收藏  举报