实验二

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

	system("pause");
	return 0;
}

  

(1)生成一个在R1到R2之间的随机数

(2)随机抽取五个学号

2、程序源码

#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);//分开后加入getchar()//
getchar();
scanf("%c",&c1);
getchar();
scanf("%c",&c2);
getchar();
scanf("%c",&c3);
getchar();
printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);//分开后加入getchar(),%f改%lf//
scanf("%lf", &x);
getchar();
scanf("%lf",  &y);
printf("x = %f, y = %lf\n",x, y);
	
		system("pause");
	return 0;
}

  

实验截图

 

3.2、程序源码

 

#include<stdio.h>
#include<stdlib.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");
	}
		system("pause");
	return 0;
}

  

实验截图

 

3.3、程序源码

 

#include<stdio.h>
#include<stdlib.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");
	}
		system("pause");
	return 0;
}

  

实验截图

 

4、程序源码

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

int main(){
	char c;
	printf("输入交通信号灯的颜色r,g或y\n");
	while(scanf("%c",&c)!=EOF)
	{switch(c)
	{
	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;
	}
	scanf("%c",&c);
	}
		system("pause");
	return 0;
}

  

实验截图

 

5、程序源码

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

int main(){
	int number,day,n;
	int i=1;
	printf("猜猜你的lucky day\n开始喽你有三次机会,猜吧(1~30)\n");
	srand(time(0));
	number = rand()%(30+1);
	
	while(i<4)
	{scanf("%d",&day);
	getchar();
	if(day==number)
	     printf("哇,猜中了\n");
	else
		{if(number<day)
			printf("你猜的日期晚了,lucky day已经过了\n");
		else
			printf("你猜的日期早了,lucky day还没到哦\n");}
	i++;
	if(day==number)
	    break;
	else
		i;
	if(i==4)
		printf("%d",number);
	else
	i;
	}
	
		system("pause");
	return 0;
}

  

实验截图

 

6、程序源码

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

int main(){
	int i,j;
	i=1;
	while(i<10)
	{i++;}
	i=1;
	while(i<10)
	{printf("\n");
	j=1;
	while(j<=i)
	{printf("%dx%d=%d\t",i,j,i*j);
	j++;}
	i++;}
	i++;
	system("pause");
	return 0;
}

  

实验截图

 

7、

实验原理

当输入为n时:
第i行,需要打印(2(n-i)-1)个字符小人
第i行,前面需要打印(i-1)个空白

程序源码

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


int main(){
	int n,m,a,i;
	i=0,m=1,a=1;
	scanf("%d",&n);
	while(i<3*n)
	{m=1;
	a=1;
	if(i%3==1)
	{
		while(m<=(i-1)/3)
		{printf(" \t");
         m++;}
        while(a<2*(n-(i-1)/3))
	    {printf("<H>\t");
		a++;}}
	else
	{if(i%3==2)
      {
	     while(m<=(i-2)/3)
		{printf(" \t");
         m++;}
        while(a<2*(n-(i-2)/3))
	    {printf("I I\t");
		a++;}}
		else
	{if(i%3==0)
      {
	     while(m<=(i/3))
		{printf(" \t");
         m++;}
        while(a<2*(n-i/3))
	    {printf(" o\t");
		a++;}}
	else
		i;
	}}
	printf("\n");
	i++;}
		system("pause");

	return 0;
}

  

实验截图

 

posted @ 2023-03-17 23:38  邓牧蝶  阅读(12)  评论(0编辑  收藏  举报