实验任务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;
}
屏幕截图

问题一:生成一个586~701之间的随机数
问题二:随机生成5个尾号为586~701的学号
实验任务2
源码
#include <stdio.h> int main() { double x, y; char c1, c2, c3; int a1, a2, a3; scanf("%d%d%d", &a1, &a2, &a3); printf("a1 = %d, a2 = %d, a3 = %d\n", a1, a2, a3); scanf("%c%c%c", &c1, &c2, &c3); printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3); scanf("%lf,%lf", &x, &y); printf("x = %lf, y = %lf\n",x, y); return 0; }
屏幕截图

实验任务3
3.1
源码
#include <stdio.h>
#include <math.h>
int main()
{
double x,ans;
scanf("%lf",&x);
ans=pow(x,365);
printf("%.2f的365次方:%.2f\n",x,ans);
return 0;
}
屏幕截图

3.2
源码
#include <stdio.h> #include <math.h> int main() { double x, ans; while(scanf("%lf", &x)!= EOF) { ans = pow(x, 365); printf("%.2f的365次方:%.2f\n", x, ans); printf("\n"); } return 0; }
屏幕截图

3.3
源码
#include <stdio.h>
#include <math.h>
int main()
{
double c, f;
while (scanf("%lf", &c) != EOF)
{
f = (9.0 / 5.0) * c + 32;
printf("摄氏度c=%.2f时,华氏度f=%.2f\n", c, f);
printf("\n");
}
return 0;
}
屏幕截图

实验4
源码
#include <stdio.h>
#include <stdlib.h>
int main()
{
char light;
while (scanf("%c", &light) != EOF)
{
getchar();
switch (light)
{
case 121:printf("wait a minute\n");break;
case 103:printf("go go go\n");break;
case 114:printf("stop!\n");break;
default:printf("something must be wrong...\n");break;
}
}
return 0;
}
屏幕截图

实验5
源码
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, i, b;
i = 1;
srand((unsigned)time(NULL));
a = rand() % (30 - 1 + 1) + 1;
printf("猜猜4月哪一天会是你的lucky day\n开始喽,你有三次机会,猜吧(1—30):");
while (i <= 3 || b == a)
{
scanf("%d", &b);
if (b == a)
printf("哇,猜中了");
else if (b < a)
printf("猜早了哦\n\n");
else if (b > a)
printf("日期已经过了哦\n\n");
if (i < 3 && a != b)
printf("再猜猜看:");
i += 1;
}
if (i > 3)
printf("还没猜对哦,你的lucky day是%d号", a);
return 0;
}
屏幕截图

实验6
源码
#include<stdio.h>
int main() {
int i, j;
for (i = 1;i <= 9; i++) {
for (j = 1;j <= i; j++) {
printf("%d*%d =%3d ", j, i, j * i);
}
printf("\n");
}
return 0;
}
屏幕截图

实验7
源码
#include<stdio.h>
int main() {
int n;
printf("input n:");
scanf("%d", &n);
for (int i = 1;i <= n; i++) {
for (int k = 1;k <= 3; k++) {
for (int j = 1;j <= i - 1; j++) {
printf(" ");
}
for (int j = 1;j <= 2 * (n - i) + 1; j++) {
if (k == 1) printf(" O ");
if (k == 2) printf("<H> ");
if (k == 3) printf("I I ");
}
printf("\n");
}
}
return 0;
}
屏幕截图

浙公网安备 33010602011771号