实验2

task1

源代码

#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);
	}
	system("pause");
	return 0;


}

运行结果截图

结论

1.从R1-R2之间随机生成一个数并赋值到number

2.以系统时间随机生成五个数组

task2

源代码

#include<stdio.h>
#include<stdlib.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 = %f, y = %lf\n",x, y);
	system("pause");
	return 0;


}

  

运行结果截图

task3

源代码

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;

}

 3_2

#include <stdio.h>
#include <math.h>
int main()
{
	double c, f;
	while(scanf("%lf", &c) != EOF)
	{
		f = 9*c/5+32;
		printf("摄氏度c = %.2f时,华氏度f = %.2f\n", c, f);
		printf("\n");
	}
	return 0;

}

  

 

运行结果截图

task4

源代码

#include <stdio.h>
int main()
{
	char x;
	while(scanf("%c", &x) != EOF)
	{
		switch(x){
		case'y':printf("wait a minutea\n");break;
		case'g':printf("go go go\n");break;
		case'r':printf("stop!\n");break;
		default:printf("something muse be wrong...\n");

		}
		getchar();
	}
	return 0;

} 

运行结果截图

task5

源代码

#include <stdio.h>
#include <stdlib.h>
int main()
{
	int x,n,i;
	x = rand() %(30)+1;
	printf("猜猜2023年4月哪一天会是你的lucky day\n开始喽,你有三次机会,");
	for(i=0;i<3;i++){
		printf("猜吧(1-30):");
		scanf("%d",&n);
		if(n==x)
			{printf("哇,你中了!!!\n");break;}
		else
			if(n<x)
				printf("你猜的时间早了哦\n");
			else
				printf("你猜的时间晚了哦\n");
			if(i==2)
				printf("次数用完啦,偷偷告诉你,4月你的lucky day是%d号\n",x);
		}
	system("pause");

	return 0;
}

  

运行结果截图

 

task6

源代码

#include <stdio.h>
#include <stdlib.h>
int main()
{
	int j,i;
	for(i=1;i<=9;i++){
		for(j=1;j<=i;j++){
			printf("%d*%d = %-2d ",j,i,i*j);}
		printf("\n");
	}
	system("pause");

	return 0;
}

  

运行结果截图

 

task7

源代码

#include<stdio.h>
int main()
{
	int n,i,y,v,a=1;
	scanf("%d",&n);
	for(i=n;i>=1;i--){
		for(v=1;v<a;v++)
			printf("\t");
		for(y=1;y<=(2*i-1);y++){
			printf(" O \t");
		}
		printf("\n");
		for(v=1;v<a;v++)
			printf("\t");
		for(y=1;y<=(2*i-1);y++){
			printf("<H>\t");
		}
		printf("\n");
		for(v=1;v<a;v++)
			printf("\t");
		for(y=1;y<=(2*i-1);y++){
			printf("I I\t");
		}
		printf("\n");
		a++;	
	}
	return 0;
}

运行结果截图

 

posted @ 2023-03-22 20:17  17-邱远鹏  阅读(13)  评论(0编辑  收藏  举报