# 实验2

//这个程序随机生成2018-2021年级的学号
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define N 5

int main()
{

srand(time(0));

for (i = 0; i < N; ++i)
{
grade = rand() % 4 + 2018;//生成2018-2021之间的年份
number = rand() % 999 + 1;//生成1-999之间的学号
}

return 0;

}

任务2

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int m, n, i;
srand(time(0));
m = rand() % 30 + 1;
printf("猜猜2022年4月的哪一天是你的幸运日\n");
printf("\n你有三次机会\n");
printf("开猜！:");
for (i = 1; i <= 3; i++)
{
scanf("%d", &n);
if (m > n)
{
printf("早了\n");
printf("再猜:");
}
else if (m < n)
{
printf("迟了\n");
printf("再猜:");
}
else
{
printf("回答正确 \n");
break;
}
}
if (m != n)
{
printf("机会已尽，正确答案是%d号", m);
}
return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
char light;
while (scanf("%c", &light) != EOF)
{
getchar();
if (light == 'r')
{
printf("stop!\n");
}
else if (light == 'g')
{
printf("go go go\n");
}
else if (light == 'y')
{
printf("wait a minute\n");
}
else
{
printf("invaild input!\n");
}
}
return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
int n, a;
double s, temp;
while (scanf("%d %d", &n, &a) != EOF)
{
temp = 0,s = 0;
for (int i = 1; i <= n; i++)
{
temp = temp * 10 + a;
s += 1.0 * i / temp;
}
printf("n=%d,a=%d,s=%f\n", n, a, s);
}
return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int i, j, n;
while (scanf("%d", &n) != EOF)
{
printf("生成一个n阶乘法表:\nn=");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d×%d=%-3d", j, i, i * j);
}
printf("\n");
}
}
return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int i, n;
while (scanf("%d", &n) != EOF)
{
printf("生成n个小人:\nn=");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
printf(" O\n");
printf("<H>\n");
printf("I I\n");
printf("\n");
}
}
return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int i, n;
while (scanf("%d", &n) != EOF)
{
printf("生成n个小人:\nn=");
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
printf("  O  ");
}
printf("\n");
for (int i = 0; i < n; i++)
{
printf(" <H> ");
}
printf("\n");
for (int i = 0; i < n; i++)
{
printf(" I I ");
}
printf("\n");
}
return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int n, j, k;
printf("input n:");
scanf("%d", &n);
for (int m = 0; m < n; m++)
{
for (j = 0; j < m; j++)
printf("    ");
for (k = 0; k < 2 * (n - j) - 1; k++)
{
printf(" O  ");
}
printf("\n");
for (j = 0; j < m; j++)
printf("    ");
for (k = 0; k < 2 * (n - j) - 1; k++)
{
printf("<H> ");
}
printf("\n");
for (j = 0; j < m; j++)
{
printf("    ");
}
for (k = 0; k < 2 * (n - j) - 1; k++)
{
printf("I I ");
}
printf("\n");
}
return 0;
}

1.任务5-任务6.2使用了类似思路，偷懒成功

2.但任务6.3... 只能说债终究是要还的

posted @ 2022-04-18 22:23  Zxc123jkl  阅读(5)  评论(1编辑  收藏  举报