实验2

实验任务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:随机生成585到701中的整数

问题2:随机生成学号202283300586到202283300701之间的学号

实验任务2

代码

#include<stdio.h>
#include<stdlib.h>
int main()
{
int a1,a2,a3;
char c1,c2,c3;
double x,y;
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 = %.6lf,y =%.6lf\n",x,y);

system("pause");
return 0;
}

截图

 

实验任务3

代码

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
double x, ans;

scanf("%lf", &x);
ans = pow(x,365);
printf("%.2f的365次方: %.2f\n" ,x, ans);
system("pause");
return 0;
}

截图

 

修改后代码

#include<stdio.h>
#include<math.h>
#include<stdlib.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;
}

截图

改编

代码

#include<stdio.h>

#include<math.h>
#include<stdlib.h>
int main()
{
double c, F;

while(scanf("%lf", &c) != EOF)
{
F = c*9/5+32;
printf("摄氏度出= %.2f时,华氏度F= %.2f\n" ,c, F);
printf("\n");
}
system("pause");
return 0;
}

截图

实验任务4

代码

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
char n;


while(scanf(" %c", &n) != EOF)
{
if(n==114)
printf("stop!\n");
else if(n==103)
printf("go go go\n");
else if(n==121)
printf("wait a minute\n" );
else
printf("something must be wrong\n");
printf("\n");


}
system("pause");
return 0;
}

截图

 

实验任务5

代码

 

{
int number,n=1,m,t;
number=rand() % (30-1+1)+1;
printf("猜猜2023年4月哪一天会是你的lucky day\n");
printf("开始咯,你有三次机会,猜吧(1-30): ");

while(n<=3)
{
printf("再猜(1-30): ");
scanf(" %d", &m);

if (m==number){
printf("哇,猜中了:-)");

break;}
else if(m<number){
printf("你猜的日期早了,你的lucky day还没到呢\n");
}
else {
printf("你猜的日期晚了,你的lucky day已经过啦\n");
}
n++;
t=m;
}
if(n>3)
printf("次数用完啦,偷偷告诉你:4月,你的lucky day是:%d" ,number);

else
printf("\n");

system("pause");
return 0;
}

截图

 

实验任务6

代码

#include<stdio.h>

#include<stdlib.h>
int main()
{
int number,t,n,m;
for(t=1;t<=9;t++)
{
for(n=1;n<=t;)
{
number=n*t;
printf("%d*%d = %2d\0", n,t,number);
printf(" ");
n++;
}
printf("\n");
}
system("pause");
return 0;
}

截图

 实验任务7

代码

#include<stdio.h>
#include<stdlib.h>
int main()
{
int j,l,h,a,x,t,n,m, y=0,e=0,r=0;
scanf("%d",&n);
for(;n>0;n--)
{

if(y>=5){ j=y;
for(y;y>=1;y--)
{
printf(" ");

}y=j+5;
}
else
y=y+5;

for(t=1;t<=(2*n-1);t++)
{
printf(" O ");

}
printf("\n");


if(e>=5){l=e;
for(e;e>=1;e--)
{
printf(" ");

}e=l+5;
}
else
e=e+5;
for(x=1;x<=(2*n-1);x++)
{
printf("<H> ");

}
printf("\n");

if(r>=5){h=r;
for(r;r>=1;r--)
{
printf(" ");

}r=h+5;
}
else
r=r+5;
for(m=1;m<=(2*n-1);m++)
{
printf("I I ");

}
printf("\n");
}
system("pause");
return 0;
}

截图

 

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