首页 > 其他分享 >实验二

实验二

时间:2023-10-16 21:37:29浏览次数:29  
标签:int break tim while 实验 printf include

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5
#define N1 374
#define N2 465
int main()
{
int number;
int i;
srand( time(0) ); 
for(i = 0; i < N; ++i) {
number = rand()%(N2 - N1 + 1) + N1;//计算num的值 
printf("202383290376%04d\n", number);//生成3个前面一部分固定的随机数 
}
return 0;
}
#include <stdio.h>

int main()
{
    char col;
    while(scanf("%s",&col) != EOF)
    {
        switch(col)
        {
            case 'r':
                printf("Stop!\n");  break;
            case 'g':
                printf("Go go go!\n");   break;
            case 'y':
                printf("Wait a minute.\n");  break;
            default:
                printf("Something must be wrong......");   break;
        }
    
    return 0;

 

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

int main()
{
    int tim = 0;
    
    srand(time(0));
    
    while(tim < 1 || tim > 30)
        {tim = rand();}
    
    int gus,i = 1;
    printf("猜猜2023年哪天是你的lucky day\n开始了,你有三次机会,猜吧(1~30):");
    scanf("%d",&gus);
    while(i <= 3)
    {    if(gus<tim)
        {   printf("你猜的日期早了,你的licky day 还没到呢。\n再猜(1~30):");
            scanf("%d",&gus);
            i++;
        }
        else if(gus>tim)
        {   printf("你猜的日期晚了,你的lucky day以及过了\n再踩(1~30):");
            scanf("%d",&gus);
            i++; 
        }
        else
        {   printf("哇猜中了=)\n");
            break;
        }
    }
    if(i == 4)
       {printf("次数用完了,偷偷告诉你:11月,你的lucky day 是%d号\n",tim);}

    return 0;

 

}

 

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

int Down(int n,int a)
{   int y = 0;
    while(n>0)
    {   y = a + y*10;
        n--;
    }
    return y;
}

int main()
{
    int n,a;
    while(scanf("%d %d",&n,&a) != EOF)
    {
        double i = 1, s = 0;
        while(i<=n)
            {
                s = s + i/Down(i,a);
                i++;
            }
        
        printf("n = %d, a = %d, s = %.6lf",n,a,s);
    }
    
    return 0;

 

}

 

标签:int,break,tim,while,实验,printf,include
From: https://www.cnblogs.com/5464665465L/p/17767942.html

相关文章

  • 实验2
    task1代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain(){10intnumber,i;1112srand(time(0));1314for(i=0;i<N;++i......
  • 实验二 c语言分支与循环基础应用编程
    实验一源代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){ intnumber; inti; srand(time(0)); for(i=0;i<N;i++) { number=rand()%(N2-N1+1)+N1; printf("20238329%04......
  • 实验二
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%(N2-N1+......
  • 实验2
    实验任务1 #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){ system("colorE5");intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(i=0;i&......
  • 实验2 C语言分支与循环基础应用编程
    一、实验目的能正确使用if语句、switch语句实现分支结构能正确使用while语句、do...while语句、for语句实现循环结构能在具体问题场景中使用嵌套分支语句和嵌套循环语句能在具体问题场景中正确区分、使用continue和break能灵活、组合使用c语句编程解决简单应用问题二、实......
  • 实验2 C语言分支与循环基础应用编程
    练习1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(i=0;i<N;++i){number=rand()%(N2-N1......
  • 实验2_C语言分支与循环基础应用编程
    1.task_11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;1314srand(time(0));1516for......
  • 实验2
    实验2task11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;1314srand(time(0));1516for(i......
  • 实验2
    实验2-11#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#include<math.h>56#defineN57#defineN13748#defineN2465910intmain()11{12intnumber;13inti;1415srand(time(0))......
  • 实验2
    #include<stdio.h>intmain(){charcolour;while(scanf("%c",&colour)!=EOF){if(colour>='a'&&colour<='z'){if(colour=='r'){prin......