首页 > 其他分享 >实验二

实验二

时间:2023-10-16 20:33:45浏览次数:27  
标签:int number 实验 printf N1 include define

task1

#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;
        printf("202383290376%04d\n", number);
    }
    
    return 0;
}

 

 

task2(有问题)

#include<stdio.h>

int main(void)
{
    char n;
    n = getchar();
    while (scanf("%c,&n") != EOF)
    {
        if (n == 'r')
        {
            printf("stop!\n");
        }
        else if (n == 'g')
        {
            printf("go go go\n");
        }
        else if (n == 'y')
        {
            printf("wait a minuate\n");
        }
        else
        {
            printf("something must be wrong\n");
        }
    }

        return 0;
}

 

task3

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

#define N 1
#define N1 1
#define N2 30

int main()
{
    int number;
    int t, i, n;

    srand(time(0));

    for (i = 0;i < N;++i) {
        number = rand() % (N2 - N1 + 1) + N1;


    }
    printf("先偷偷把答案告诉你:%d\n", number);
    printf("猜猜2023年11月那天会是你的lucky day\n");
    printf("那么现在开始喽,你有三次机会,猜吧:");
    for (t = 1;t <= 3;t++) {

        scanf("%d", &n);

        if (n < number) {
            printf("你猜的日期早啦,还没到呢\n");

        }
        else if (n > number) {
            printf("你猜的日期晚啦,已经过了\n");
        }
        else {
            printf("恭喜你猜对啦\n");break;
            return n;
        }
    }
     printf("次数用完辣,偷偷告诉你,你的lucky day是:%d",number);
    return 0;
}

 

 

task4

#include<stdio.h>
#include<math.h>
int main()
{
    int n, a;
    while (scanf("%d%d", &n, &a) != EOF)
    {
        double s = 0;
        double t = 0;
        for (int i = 1; i <= n; ++i) {
            t = t + pow(10, i - 1) * a;
            s = s + i / t;
        }
        printf("n=%d,a=%d,s=%f", n, a, s);
    }
}

 

 

task5

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

 

task6

 

标签:int,number,实验,printf,N1,include,define
From: https://www.cnblogs.com/Bulletproof-Picasso/p/17768280.html

相关文章

  • 实验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......
  • 实验二
    一.实验任务一源码#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)+......
  • 实验二
    任务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+1)+N1;pri......
  • 实验二
    task1.c源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;1314srand(time(0));1516for(i=0;i......