# 实验任务一

### 代码

 1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <time.h>
4 #define N 5
5 #define R1 586
6 #define R2 701
7 int main()
8 {
9     int number;
10     int i;
11     srand(time(0));
12     for (i = 0; i < N; ++i)
13     {
14         number = rand() % (R2 - R1 + 1) + R1;
15         printf("20228330%04d\n", number);
16     }
17     return 0;
18 }

### 实验结论

line18是在586到701任取一个数字，并赋值给number

# 实验任务二

### 代码

 1 #include<stdio.h>
2 int main()
3 {
4     double x, y;
5     char c1, c2, c3;
6     int a1, a2, a3;
7     scanf_s("%d%d%d", &a1, &a2, &a3);//缺少地址运算符//
8     printf("a1 = %d, a2 = %d, a3 = %d\n", a1, a2, a3);
9     getchar();//"\n"可作为一个字符被读，所以要先去除上一句的“\n”//
10     scanf("%c%c%c",&c1,&c2,&c3);
11     printf("c1 = %c, c2 = %c, c3 = %c\n", c1,c2,c3);
12     scanf_s("%lf,%lf", &x, &y);
13     printf("x = %lf, y = %lf\n", x, y);//数据类型错误//
14     return 0;
15 }

# 实验任务三

### 代码

 1 #include <stdio.h>
2 #include <math.h>
3 int main()
4 {
5     double x, ans;
6     int flag = 1;
7     char anss;
8     while (flag)
9     {
10         scanf_s("%lf", &x);
11         ans = pow(x, 365);
12         printf("%.2f的365次方: %.2f\n", x, ans);
13         getchar();
14         printf("continue?(y/n):");
15         anss = getchar();
16         if (anss == 'n' || anss == 'N')
17             flag = 0;
18         getchar();
19
20     }
21     return 0;
22 }

### 代码

 1  #include <stdio.h>
2  #include <math.h>
3 int main()
4 {
5     double x, ans;
6     while (scanf_s("%lf", &x) != EOF)
7     {
8         ans = 9 * x / 5 + 32;
9         printf("摄氏度c=%.2f时，华摄氏度f=%.2f\n", x, ans);
10         printf("\n");
11     }
12     return 0;
13 }

# 实验任务四

### 代码

 1 #include <stdio.h>
2 #include <math.h>
3 int main()
4 {
5     char color;
6     do
7     {
8         color = getchar();
9         getchar();
10         switch (color)
11         {
12         case'r':printf("stop!\n"); break;
13         case'g':printf("go go go\n"); break;
14         case'y':printf("wait a minute\n"); break;
15         case EOF:break;
16         default:printf("something must be wrong\n");
17             break;
18         }
19     } while (color != EOF);
20     return 0;
21 }

# 实验任务五

### 代码

#include <stdio.h>
#include <math.h>
#include <time.h>
int main()
{
int num, i, n;
srand(time(0));
num = rand() % (30 - 1 + 1) + 1;
printf("猜猜2023年4月哪一天是你的lucky day\n");
printf("\n");
printf("开始喽，你有三次机会，猜吧（1~30）：");
scanf_s("%d", &n);
printf("\n");
for(i=1;i<3;i++)
{
if (n > num)
printf("你猜的日期晚了，你的lucky day已经过了\n");
else if (n < num)
printf("你猜的日期早了，你的lucky day还没到呢\n");
else
{
printf("哇，猜中了:-)");
break;
}

printf("\n");
printf("再猜（1~30）：");
scanf_s("%d", &n);
printf("\n");
}
if (n != num)
printf("次数用完啦。偷偷告诉你：4月，你的lucky day是%d号",num);
return 0;
}

# 实验任务六

### 代码

 1 int main()
2 {
3     int i, n,s;
4     for (n = 1; n <= 9; n++)
5     {
6         for (i = 1; i <= n; i++)
7         {
8             s = n * i;
9             printf("%dx%d=%2d  ", n, i, s);
10         }
11         printf("\n");
12     }
13     return 0;
14 }

### 实验总结

%-2d是向左对齐，%2d则为向右对齐，而%.2d则是将所有乘积化为两位数，比如9=09。

# 实验任务七

### 代码

 1 #include <stdio.h>
2 #include <math.h>
3 #include <time.h>
4 int main()
5 {
6     int n,i,j,k,m=0;
7     printf("input n:");
8     scanf_s("%d", &n);
9     const char* str[] = { " O ","<H>","I I" };
10     for (; n > 0; n--)
11     {
12
13         for (i = 0; i < 3; i++)
14         {
15             for (k = 1; k <= m * 6; k++)
16                 printf(" ");
17             for (j = 0; j < 2 * n - 1; j++)
18                 printf("%-6s", str[i]);
19             printf("\n");
20
21         }
22         printf("\n");
23         m++;
24     }
25 return 0;
26 }

### 实验结论

posted @ 2023-03-17 10:33  崩崩大圆帽  阅读(8)  评论(0编辑  收藏  举报