实验二

点击查看代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5
int main()
{
	int number;
	int i;
	srand( time(0) ); // 以当前系统时间作为随机种子
	for(i = 0; i < N; ++i) {
		number = rand()%65 + 1;
		printf("20238331%04d\n", number);
	}
	system("pause");
	return 0;
}

line15的作用是给number随机赋值一个[1,65]之间的整数;
代码的作用是随机生成五个学号,学号范围202383310001~202383310065.

点击查看代码
#include <stdio.h>
#include <stdlib.h>
int main(){
	char a;
	while(scanf("%c",&a)!=EOF){
		switch(a){
			case 'r':printf("stop!\n");break;
			case 'g':printf("go go go\n");break;
			case 'y':printf("wait a minute\n");break;
			default :printf("something must be wrong...\n");break;
		}
		getchar();
	}
	system("pause");
	return 0;
}

点击查看代码
#include <stdio.h>
#include <stdlib.h>
int main(){
	int number,a;
	int i;
	number = rand()%30+1;
	printf("猜猜2024年5月哪一天会是你的lucky day\n");
	printf("开始喽,你有三次机会,猜吧(1-31):");
	for(i=1;i<=2;++i){
		scanf("%d",&a);
		if(a==number){
			printf("哇,猜中了");
			system("pause");
			return 0;
		}else if(a>number){
			printf("你猜的日期晚了,你的lucky day在前面哦\n");
			
		}else if(a<number){
			printf("你猜的日期早了,你的lucky day还没到呢\n");
		}
		printf("再猜(1-31):");
	}
	scanf("%d",&a);
	if(a==number){
		printf("哇,猜中了");
		system("pause");
		return 0;
	}else if(a>number){
		printf("你猜的日期晚了,你的lucky day在前面哦\n");
	}else if(a<number){
		printf("你猜的日期早了,你的lucky day还没到呢\n");
	}
	printf("次数用完了,偷偷告诉你,你的lucky day是%d号",number);
	system("pause");
	return 0;
}

点击查看代码
#include <stdio.h>
#include <stdlib.h>
int main(){
	int i,j,n,a,b;
	while(scanf("%d%d",&n,&a)!=EOF){
		double s=0;
		for(i=1;i<=n;i++){
			b=0;
			for(j=1;j<=i;j++){
				b=b*10+1;
			}
			s+=1.0*i/(a*b);
		}
		printf("n=%d,a=%d,s=%f\n",n,a,s);
	}
	system("pause");
	return 0;
}

点击查看代码
#include <stdio.h>
#include <stdlib.h>
int main(){
	int i,j;
	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;
}

点击查看代码
#include <stdio.h>
#include <stdlib.h>
int main(){
	int i,j,n;
	printf("input n:");
	scanf("%d",&n);
	for(i=n;i>0;i--){
		for(j=1;j<=n-i;j++){
			printf("        ");
		}
		for(j=1;j<=2*i-1;j++){
			printf(" o \t");
		}
		printf("\n");
		for(j=1;j<=n-i;j++){
			printf("        ");
		}
		for(j=1;j<=2*i-1;j++){
			printf("<H>\t");
		}
		printf("\n");
		for(j=1;j<=n-i;j++){
			printf("        ");
		}
		for(j=1;j<=2*i-1;j++){
			printf("I I\t");
		}
		printf("\n");
	}
	system("pause");
	return 0;
}

posted @ 2024-04-10 21:48  星軌xx  阅读(2)  评论(0编辑  收藏  举报