首页 > 其他分享 >实验2

实验2

时间:2024-04-14 23:11:19浏览次数:19  
标签:include int -- 实验 printf main

实验1

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

#define N 5

int main()
{
    int number;
    int i;
    
    srand(time(0));
    
    for(i=0;i<N;++i){
        number=rand()%65+1;//控制随机数的范围从1~66 
        printf("20238331%04d\n",number);
    }
    return 0;
 } 
 //随机生成5个学生学号 

实验2

#include<stdio.h>

int main()
{
    char n;
    while(1)
    {
        n=getchar();
        getchar();
        switch(n)
        {
            case 'r':printf("stop!");break;
            case 'g':printf("go go go");break;
            case 'y':printf("wait a minute");break;
            default:printf("something must be wrong...");break;
        }
        printf("\n");
    }
    return 0;
 } 

实验3

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

int main(){
    int number,m,i;
    srand(time(0));
    printf("猜猜2024年5月哪一天会是你的lucky day");
    number=rand()%30+1;
    printf("\n");
    printf("开始喽,你有三次机会,猜吧(1~31):");
    scanf("%d",&m);
    for(i=0;i<2;++i)
    { 
        if(m>number)
            {
                printf("你猜的日期晚了,你的lucky day在前面哦\n再猜(1~31):");
                scanf("%d",&m); 
            }
        else if(m<number)
            {
                printf("你猜的日期早了,你的lucky day还没到呢\n再猜(1~31):");
                scanf("%d",&m); 
            }
        else
            {
                printf("哇,猜中了:-)");
                break; 
            }
    }
    if(i==2)
        printf("次数用完啦。偷偷告诉你,5月你的lucky day是%d",number);
    return 0; 
}

 

实验4

#include<stdio.h>

int main()
{
    int n,a,i,m=0;
    double s=0;
    while(1)
    {
        scanf("%d %d",&n,&a);
        for(i=1;i<=n;i++)
        {
            m=m*10+a;
            s=s+1.0*i/m;
        }
        printf("n=%d,a=%d,s=%lf",n,a,s);
        printf("\n");
    }
    return 0;
}

 

实验5

#include<stdio.h>

int main()
{
    int v,l,c;
    for(c=1;c<=9;++c)
    {
        for(l=1;l<=c;++l)
        {
            printf("%d*%d=%d\t",l,c,l*c);
        }
        printf("\n");
    }
    return 0;
}

实验6

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n;
    printf("input n:");
    scanf("%d",&n);
    for(int i=n;i>=1;i--)
    {
        for(int j=n-i;j>0;j--)
            printf("      ");
        for(int j=1;j<=2*i-1;j++)
            printf(" O    ");
        printf("\n");
        for(int j=n-i;j>0;j--)
            printf("      ");
        for(int j=1;j<=2*i-1;j++)
            printf("<H>   ");
        printf("\n");
        for(int j=n-i;j>0;j--)
            printf("      ");
        for(int j=1;j<=2*i-1;j++)
            printf("I I   ");
        printf("\n");
    }
    return 0;
}

 

标签:include,int,--,实验,printf,main
From: https://www.cnblogs.com/wp40032880/p/18134894

相关文章

  • 实验2
    TASK1点击查看代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){ intnumber; inti; srand(time(0)); for(i=0;i<N;++i){ number=rand()%65+1; printf("2023833%04d\n",number); } ret......
  • 实验二
    task1点击查看代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("202......
  • 实验二。
    include<stdio.h>include<stdlib.h>include<time.h>defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",number);}return0;}问题一:一到六......
  • 实验2 C语言分支与循环基础应用编程
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){ intnumber; inti; srand(time(0)); for(i=0;i<N;++i) { number=rand()%65+1; printf("20238331%04d\n",number); } return0;......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;//生成一个1-65之间的随机数printf("20238331%04d\n",......
  • 第二次实验
    练习一:line15是在1~65的范围内随机取数这个程序生成202383310001~202383310065之间的学号练习二:include<stdio.h>intmain(){charcolor;while(scanf("%c",&color)!=EOF){ switch(color){ case'r':printf("stop!\n"); break; case'g�......
  • 实验二
    项目1代码`#include<stdio.h>include<stdlib.h>include<time.h>defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",number);}sys......
  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){ intnumber; inti; srand(time(0)); for(i=0;i<N;i++){ number=rand()%65+1; printf("20238331%04d\n",number); } return0;}#i......
  • 实验2 C语言分支与循环基础应用编程
    任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;//生成一个1-65之间的随机数printf("20238331%04d\n&q......
  • 实验二
    任务一include<stdio.h>include<stdlib.h>include<time.h>defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){ number=rand()%65+1; printf("20238331%04d\n",number);}return0;}问题一:在一到六十五之......