实验任务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之间的随机数
问题二:生成五个202283300586~202283300701之间的学号

实验任务2

实验代码

#include <stdio.h>

int main(){
	double x, y;
	char c1, c2, c3;
	int a1, a2, a3;
	
	scanf("%d%d%d", &a1, &a2, &a3);
	getchar();
	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

实验代码1

#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;
} 

实验代码2

#include <stdio.h>
#include <math.h>

int main(){
	double x, ans;
	
	while(scanf("%lf", &x) != EOF){
	
	ans = 9.0/5*x + 32;
	printf("摄氏度c = %.2f时,华氏度f = %.2f", x, ans);
	printf("\n");
}
	return 0;
} 

实验结论


实验任务4

实验代码

#include <stdio.h>

int main(){
	char light,r,g,y;
	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("something must be wrong...\n");
	}
	
	return 0; 
}

实验结论

实验任务5

实验代码

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(){
	srand(time(0));
	
	int a = rand()%30 + 1;
	int x;
	int i=1;
	printf("猜猜2023年4月哪一天会是你的lucky day\n\n");
	printf("开始喽,你有三次机会,猜吧(1~30):");
	
	while(i++<4){
		scanf("%d", &x); 
		if(x==a){
			printf("哇,猜中了:-)");
			break;}
		else if(x<a)
			printf("你猜的日期早了,你的lucky day还没到呢\n\n");
		else
			printf("你猜的日期晚了,你的lucky day已经过啦\n\n") ;
		if(i<3)
		printf("再猜(1~30):");
	}
return 0;
}

实验结论



实验任务6

实验代码

#include <stdio.h>
int main()
{
	int i,j,n;
	for(i = 1; i <= 9; i++)
	{	
		for(j = 1; j <= i; j++)
		{	
			n = i * j;
			printf("%d×%d = %d  ",i,j,n);
		}
		printf("\n");
	}
	
	return 0;
}

实验结论

实验任务7

实验代码

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

实验结论