首页 > 其他分享 >实验2

实验2

时间:2023-03-20 23:33:17浏览次数:30  
标签:main int scanf printf 实验 ans include

一.任务1

 

#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 - R2 + 1) + R1;
        printf("20228330%04d\n", number);
    }

    return 0;
}

 

 

 

问题:得到586~701之间的任一随机数;使得出一个学号。

 

二.任务2

 

#include <stdio.h>

int main()
{
    double x, y;
    char c1, c2, c3;
    int a1, a2, a3;

    scanf_s("%d%d%d", &a1, &a2, &a3);
    printf("a1 = %d, a2 = %d, a3 = %d\n", a1, a2, a3);

    getchar();

    scanf_s("%c%c%c", &c1, &c2, &c3);
    printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);

    getchar();

    scanf_s("%lf,%lf", &x, &y);
    printf("x = %lf, y = %lf\n", x, y);

    return 0;
}

 

 

 

 

 三.任务3

1)

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

int main()
{
    double x, ans;

    scanf_s("%lf", &x);
    ans = pow(x, 365);
    printf("%.2f的365次方:%.2f\n", x, ans);

    return 0;

}

 

 

 

 

 

 

2)

 

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

int main()
{
    double x, ans;

    while (scanf_s("%lf", &x) != EOF)
    {
        ans = pow(x, 365);
        printf("%.2f的365次方:%.2f\n", x, ans);
        printf("\n");
    }
    return 0;

}

 

 

 

 

 

 

摄氏度华氏度转换

 

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

int main()
{
    double F, C;

    while (scanf_s("%lf", &C) != EOF)

    {
        F =
            9 /(double) 5 * C + 32;
        printf("摄氏度c=%.2f时,华氏度f=%.2f\n", C, F);
    }
    return 0;

}

 

 

 

 

 

四.任务4

 

#include <stdio.h>

int main() {

    char ans;

    while (scanf_s("%c", &ans) != EOF) {
        getchar();
        if (ans == 'r') printf("stop!\n");
        else if (ans== 'g') printf("go go go\n");
        else if (ans == 'y') printf("wait a minute\n");
        else printf("something must be wrong...\n");
    }


    return 0;
}

 

 

 

五.任务5

 

#include<stdio.h>

int main()
{
int d,a;
d = rand() % 30 + 1;

printf("猜猜2023年4月哪一天会是你的lucky day\n");

printf("开始喽,你有三次机会,猜吧(1~30):\n");

scanf_s("%d", &a);

if (a == d)
{
    printf("哇,猜中了:-)");
}

else
{
    if (a > d)
        printf("你猜的日期晚了,你的lucky day已经过啦\n");
    if (a < d)
        printf("你猜的日期早了,你的lucky day还没到呢\n");
    printf("再猜猜(1~30):\n");
    scanf_s("%d", &a);
    
    if (a == d)
    {
        printf("哇,猜中了:-)");
    }

    else
    {
        if (a > d)
            printf("你猜的日期晚了,你的lucky day已经过啦\n");
        if (a < d)
            printf("你猜的日期早了,你的lucky day还没到呢\n");
        printf("再猜猜(1~30):\n");
        scanf_s("%d",&a);
        
        if (a == d)
        {
            printf("哇,猜中了:-)");
        }
        else
        {
            if (a > d)
                printf("你猜的日期晚了,你的lucky day已经过啦\n");
            if (a < d)
                printf("你猜的日期早了,你的lucky day还没到呢\n");
            printf("次数用完啦。偷偷告诉你:4月,你的lucky day是%d\n", d);
        }

    }
}
    return 0;
}

 

 

 

 

六.任务6

 

#include<stdio.h>

int main()
{
    int i, j;

    for (i = 1;i <= 9;i++)
    {
        for (j = 1;j <= i;j++) {
            printf("%d*%d=%2d  ", j, i, j * i);
        }
        printf("\n");
    }
    return 0;
}

 

 

七.任务7

 

#include<stdio.h>

int main()
{
    int n, i, t;
   
    printf("input:");
    scanf_s("%d", &n);
   
    for (i = 1;i <= n;i++)
    {
        for (t = 1;t <= i - 1;t++)
        
            printf("\t");
        
        for (t = 1;t <= (n - i) * 2 + 1;t++)
        
            printf(" O \t");
        
        printf("\n");

        for (t = 1;t <= i - 1;t++)
        
            printf("\t");
        

        for (t = 1;t <= (n - i) * 2 + 1;t++)
        
            printf("<H>\t");
        
        printf("\n");

        for (t = 1;t <= i - 1;t++)
       
            printf("\t");
       

        for (t = 1;t <= (n - i) * 2 + 1;t++)
       
            printf("I I\t");
     
        printf("\n");
    }

  
    return 0;
}

 

 

 

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

相关文章

  • 实验2
    实验任务1代码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;s......
  • 蓝桥楼赛第9期-修复未正确实现的实验类 题解
    题目描述程序存放的位置/home/shiyanlou/lab.py;实验类名应该为Lab;实验对象中不能插入重复标签;Python中对象引用问题,尤其如复合对象list,dict,tuple的......
  • 实验2
    实验任务1代码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){ intnumber; inti; srand(time(0)); for(......
  • 实验2 C语言输入输出和控制语句应用编程
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand(time(0));......
  • 实验二
    实验任务1源代码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 开启一个 A/B 实验到底有多简单?
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 火山引擎A/B测试平台DataTester孵化于字节跳动业务内部,在字节跳动,“万事皆A......
  • 心理学-进入心流状态的实验
    问题表现记录近期在改进的地方:如何让自己的心,静下来具体的表现:学习上,一点小小的任务完成,就会特别兴奋,导致不能继续做事;面对大量的学习规划任务,没有耐心去一步步的推进......
  • 软件测试实验-黑盒测试
     序号输入数据覆盖等价类输出12009、12、2236星期322022、3、14226星期132008、3、01316输入日期无效42022、6、e2422输入日期无......
  • 实验2
    实验任务2task1代码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){ intnumber; inti; srand(ti......
  • 实验2
    1、实验任务1源代码及运行结果截图:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumb......