首页 > 其他分享 >实验2

实验2

时间:2023-03-22 20:36:21浏览次数:36  
标签:include return int scanf 实验 printf main

#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);
        
    }
    return 0;
}

结论:问题一:随机生成一个在0586到0701之间的整数

问题二:根据时间随机生成五个四位整数和20228330组合生成学号

task2:

#include <stdio.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 = %f,y = %lf\n",x,y);
    
    return 0; 
}

task3:

3-2:

#include <stdio.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");
    }
    return 0;
}

3-3:

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

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

task4:

#include <stdio.h>
int main()
{
    char color;
    printf("enter color(r,g,y):");
    color = getchar();
    
    switch(color){
        case'r':printf("stop!\n");break;
        case'g':printf("go go go\n");break;
        case'y':printf("wait a minute\n");break;
    }
    return 0;
}

task5:

#include <stdio.h>
#include <time.h>
int main()
{
    int i = 1;
    int d,x;
    srand(time(0));
    d = rand()%30+1;
    printf("猜猜4月哪一天是你的Lucky day(三次机会):");

    scanf("%d",&x);
    if(x == d){
        printf("猜对了");
        
    }
    else{
        if(x < d){printf("早了");}
        if(x > d){printf("晚了");}
        printf("再试一次\n") ;
        
        scanf("%d",&x);
        if(x == d){
        printf("猜对了");
        
    }
    else{
        if(x < d){printf("早了");}
        if(x > d){printf("晚了");}
        printf("再试一次\n") ;
        scanf("%d",&x);
        if(x == d){
        printf("猜对了");
        
    }
    else{
        if(x < d){printf("早了");}
        if(x > d){printf("晚了");}
        
        printf("次数用完了,你的lucky day是%d号\n",d);
        
    }

}
}
    return 0;
}

task6:

#include <stdio.h>
int main(){
    int i,j,k;
    for(i = 1;i <= 9;i++){    
    for(k = 1;k <= 9-i;k++)
    printf("");
    for(j = 1;j <= i;j++)
    printf("%d*%d= %2d\t",i,j,i*j );
    printf("\n");
}
return 0;
}

task7:

#include <stdio.h>
int main(){
    
    int i,j,k;
    printf("enter line:");
    scanf("%d",&k);

    for(i = 1;i<=k;i++){
        for(j = 1;j<=i-1;j++)
            printf("\t");
        
        for(j = 1;j<=(k-i)*2+1;j++)
        printf(" o \t");
        printf("\n");
        
        for(j = 1;j <=i-1;j++)
        printf("\t");
        for(j = 1;j <= (k - i)*2+1;j++)
        printf("<H>\t");
        printf("\n");
        for(j = 1;j <= i-1;j++)
        printf("\t");
        for(j = 1;j<=(k-i)*2+1;j++)
        printf("I I\t");
        printf("\n\n");
    }
    return 0;
}

结论:第i行需要打印(2i-1)个小人;打印(i-1)个"\t"

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

相关文章

  • 实验2
    实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验2 字符串与列表
    1x='nbaFIFA'2print(x.upper())3print(x.lower())4print(x.swapcase())5print()67x='abc'8print(x.center(10,'*'))9print(x.ljust(10,'*'))......
  • 实验2
    x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))print(x.ljust(10,'*'))print(x.rjust(10,'*'))......
  • 实验二
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sra......
  • 实验2
    实验任务1  问题一:line18将几个随机数组合起来问题二:根据当时的电脑时间,随机生成四个四位数 实验任务2 #include<stdio.h>#include<stdlib.h>intmain()......
  • 实验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,一切可......