实验二
task 1
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 5
#define R1 586
#define R2 701
int main()
{
int number;
int i;
srand(time(0));
for (i = 0; i < N; ++i)
{
number = rand()%(R2 - R1 + 1) + R1;
printf("20228330%04d\n", number);
}
return 0;
}
产生一个R2-R1到R1的随机数
随机选取学号尾数在586到701之间的学生
task 2
#include<stdio.h>
int main()
{
double x, y;
char c1, c2, c3;
int a1, a2, a3;
scanf_s("%d%d%d", &a1, &a2, &a3);
//scanf_s("%d%d%d", a1, a2, a3);
printf("a1=%d a2=%d a3=%d\n", a1, a2, a3);
getchar();
scanf_s("%c%c%c", &c1,1, &c2,1, &c3,1);
printf("c1=%c c2=%c c3=%c\n", c1, c2, c3);
scanf_s("%lf%lf", &x, &y);
scanf_s("%lf%lf", &x, &y);
//printf("x=%f y=%lf\n", x, y);
//printf("x=%f y=%lf\n", x, y);
return 0;
}
task 3
#include<stdio.h>
#include<math.h>
int main()
{
double x, ans;
while (scanf_s("%lf", &x) != EOF)
{
ans = pow(x, 365);
printf("%.2f的365次方:%.2f\n", x, ans);
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<math.h>
int main()
{
double F, C;
while (scanf_s("%lf",&C) != EOF)
{
F = (9 * C) / 5 + 32;
printf("摄氏度C=%.2lf时,华氏度F=%.2lf\n", C, F);
}
return 0;
}
task 4
#include<stdio.h>
int main()
{
char x;
while (scanf_s("%c", &x,1) != EOF)
{
getchar();
switch (x)
{
case'y':printf("wait a minute\n"); break;
case'g':printf("go go go\n"); break;
case'r':printf("stop\n"); break;
default:printf("something must be wrong\n"); break;
}
}
return 0;
}
task 5
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
int d, x, y;
srand(time(0));
d = rand() % 31 + 1;
printf("猜猜2023年4月哪一天会是你的lucky day\n开始咯,你有三次机会,猜吧(1-30):");
scanf_s("%d", &x);
if (x < d)
printf("你猜的日期早了,你的lucky day还没到呢\n");
else
{
if (x == d)
printf("哇,猜中了\n");
else
printf("你猜的日期晚了,你的lucky day已经过期了\n");
}
printf("再猜(1-30)");
scanf_s("%d", &x);
if (x < d)
printf("你猜的日期早了,你的lucky day还没到呢\n");
else
{
if (x == d)
printf("哇,猜中了\n");
else
printf("你猜的日期晚了,你的lucky day已经过期了\n");
}
printf("再猜(1-30)");
scanf_s("%d", &x);
if (x < d)
printf("你猜的日期早了,你的lucky day还没到呢\n\n次数用完啦,偷偷告诉你:4月,你的lucky day是%d", d);
else
{
if (x == d)
printf("哇,猜中了\n");
else
printf("你猜的日期晚了,你的lucky day已经过期了\n\n次数用完啦,偷偷告诉你:4月,你的lucky day是%d",d);
}
}
task 6
#include<stdio.h>
#include<stdlib.h>
int main()
{
int x, y, ans, n;
x = 1;
y = 1;
for (; y <= 9; y++)
{
for (; x <= y; x++)
{
ans = x * y;
printf("%d×%d=%d ", x, y, ans);
}
printf("\n");
x = 1;
}
return 0;
}
task 7
需要2n-2i+1
i-1个空白
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int m, x, y, n, k;
scanf_s("%d", &m);
x = 1;
y = 1;
k = m;
for (;m!=0;m = m - 1)
{
for (n=2*k-y; x <= n;)
if (x >= y)
{
for (; x <= n; x++)
{
printf(" o ");
}
}
else
{
for (; x < y; x++)
printf(" ");
}
x = 1;
printf("\n");
for (n = 2 * k - y; x <= n;)
if (x >= y)
{
for (; x <= n; x++)
{
printf("<H> ");
}
}
else
{
for (; x < y; x++)
printf(" ");
}
x = 1;
printf("\n");
for (n = 2 * k - y; x <= n;)
if (x >= y)
{
for (; x <= n; x++)
{
printf("I I ");
}
printf("\n");
}
else
{
for (; x < y; x++)
printf(" ");
}
x = 1;
printf("\n");
y = y + 1;
}
return 0;
}