arkland0913

实验2

实验任务1

 

 问题一:line18将几个随机数组合起来

问题二:根据当时的电脑时间,随机生成四个四位数

 

实验任务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); 

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

system("pause");
return 0;
}

 

 

 

实验任务3

 

 

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

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

	return 0;
}

  

 

 

实验任务四:

 

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

int main() 
{    
    char n;
    while(1)
    
    {
        scanf("%c",&n)!=EOF;
        if(n=='y')
    {printf("wait a moment\n");}
        else if(n=='g')
    {printf("Gogogo\n");}
        else if(n=='r')
    {printf("stop!\n");}
        else 
    {printf("wrong\n");}
    }
    system("pause");
return 0;
}

 

 

 

//怎样才能避免多判断输出一次?

 

实验任务五:

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


int main()
{
int n,t,r;
srand(time(0));
t=rand()%(30-1+1)+1;
printf("猜猜2023年4月哪一天是你的luckyday?");

for(r=0;r<3;r++)

{
printf("开始了,你有三次机会,猜吧(1~30):");
scanf("%d",&n);
printf("\n");

{
if (n==t)
printf("哇,猜中了!");break;


if(n<t)
printf("猜的小了,你的luckyday还没到。");

if(n>t)
printf("猜的大了,你的luckyday已经过了。");


}
printf("再猜一猜。");
printf("\n");


}
printf("次数用完了,告诉你吧,你的luckyday是%d。",t);

system("pause");

return 0;
}

 

实验截图:

 

 

 //怎样在最后一次判断时跳出for的大小判断呢?

 

实验任务六:

 

 

 

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

int main()

{
    int a,b;
    for(a=1;a<=9;a++)
    {
        for(b=1;b<=a;b++)
            printf("%d*%d=%d  ",a,b,a*b);
        printf("\n");
    
    }


     system("pause");

     return 0;

}

 

实验任务七

#include<stdio.h>
#include<stdlib.h>
#include <stdio.h>
int main()
{
 int a,b,c,d;
 printf("input a:");
 scanf("%d", &a);
 for (b= 1; b<=a; b++) {

        for (d= 1; d<= 3; d++) {

            for (c= 1; c<= b - 1; c++) 
            printf("     ");
            

            for (c= 1; c<= (a -b)*2 + 1; c++) {
                if(d==1)
                    printf(" O   ");
                if(d==2)
                    printf("<H>  ");
                if(d==3)
                    printf("I I  ");
            }
            printf("\n");
        }
    }
 system("pause");
    return 0;
}

 

 

posted on 2023-03-21 21:48  202283300646郝遥  阅读(30)  评论(0)    收藏  举报

导航