首页 > 其他分享 >实验2

实验2

时间:2023-03-21 21:57:16浏览次数:23  
标签:include int scanf 实验 printf main

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

 

 

标签:include,int,scanf,实验,printf,main
From: https://www.cnblogs.com/arkland0913/p/17222956.html

相关文章

  • 实验2
    TASK1//程序作用:随机生成五个学号#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnu......
  • 实验二
    实验任务1程序源码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验二
      实验任务1task1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineR2701#defineN5#defineR1586intmain(){ intnumber; int......
  • 实验2
    实验一程序源码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 跟着字节AB工具DataTester,5步开启一个实验
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 火山引擎A/B测试平台DataTester孵化于字节跳动业务内部,在字节跳动,“万事皆A/B,一切可......
  • 跟着字节AB工具DataTester,5步开启一个实验
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 火山引擎A/B测试平台DataTester孵化于字节跳动业务内部,在字节跳动,“万事皆A/B,......
  • 实验二
    试验任务一 程序源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;i......
  • 实验一 密码引擎-1-OpenEuler-OpenSSL编译
    实验一密码引擎-1-OpenEuler-OpenSSL编译0.安装Ubuntu和OpenEuler虚拟机1.下载最新的OpenSSL源码(1.1版本)2.用自己的8位学号建立一个文件夹,cd你的学号,用pwd获得绝......
  • 实验一 密码引擎-1-OpenEuler-OpenSSL编译
    0.安装Ubuntu和OpenEuler虚拟机安装openEuler-20.09安装登入openEuler系统1.下载最新的OpenSSL源码(1.1版本)Ubuntu22.04OpenSSL1.1.1tUbuntu最新版本下载参见......
  • 实验一 密码引擎-1-OpenEuler-OpenSSL编译
    任务详情0.安装Ubuntu和OpenEuler虚拟机下载最新的OpenSSL源码(1.1版本)用自己的8位学号建立一个文件夹,cd你的学号,用pwd获得绝对路径参考https://www.cnblogs.......