首页 > 其他分享 >实验2

实验2

时间:2023-03-16 23:24:56浏览次数:32  
标签:include int scanf 实验 printf main day

#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;
}

实验1:answer1:line18的作用生成从R1~R2范围的一个随机数

             answer2:整个程序的作用是生成从586到700的任意5个随机数

#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);
    c1 = getchar();//改错
    c2 = getchar();//改错
    c3 = getchar();//改错
    scanf_s("%c%c%c", &c1, &c2, &c3);
    printf("c1=%c,c2=%c,c3=%c\n", c1, c2, c3);
    scanf_s("%lf%lf", &x,&y);//改错
    printf("x=%f,y=%lf\n",x,y);


    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 c, ans;
    while (scanf_s("%lf", &c) !=EOF)
    { 
    ans = 9*c/5+32;
    printf("摄氏度c=%.2f时,华氏度f=: %.2f\n", c, ans);
    printf("\n");
    }



    return 0;
}

 

 

实验3:如上图

#include <stdio.h>
#include <math.h>
int main()
{
    char c;
    while (scanf_s("%c", &c) !=EOF)
    { 
    
        switch(c) {
        case 'r':printf("%s", "stop!\n"); break;


        case'g':printf("%s", "go go go\n"); break;

        case'y':printf("%s", "wait\n"); break;

        default:printf("%s", "something must be wrong\n"); break;
        }
    }



    return 0;
}

实验4:如上图

 

#include <stdio.h>
#include <math.h>
int main()
{
    int day,gd;
    day = rand() % 31;
    printf("%s", "开始了,你有两次机会");
    scanf_s("%d", &gd);
    
    if (gd < day) {
        printf("%s", "你猜的日期早了,lucky day还没到呢\n");
        printf("%s", "再猜\n");
        scanf_s("%d", &gd);

    }
    else if (gd > day) {
        printf("%s", "你猜的日期晚了,lucky day已经过啦\n");
        printf("%s", "再猜\n");
        scanf_s("%d", &gd);

    }
    else {
        printf("%s", "你猜对啦\n");
        

    }
    printf("%s", "机会用完了,悄悄告诉你你的luckyday是");
    printf("%d", day);



    return 0;
}

实验5:如上图

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



    return 0;
}
    

实验6:如上图

#include<stdio.h>
int main()
{

    int n;
    printf("input n:");
    scanf_s("%d", &n);
    for (int i = n; i > 0; i--)
    {
        for (int j = 0; j < n - i; j++)
        {
            printf("\t");

        }
        for (int k = 0; k < 2 * i - 1; k++)
        {
            printf(" O \t");

        }
        printf("\n");
        for (int j = 0; j < n - i; j++)
        {
            printf("\t");

        }
        for (int k = 0; k < 2 * i - 1; k++)
        {
            printf("<H>\t");

        }
        printf("\n");
        for (int j = 0; j < n - i; j++)
        {
            printf("\t");

        }
        for (int k = 0; k < 2 * i - 1; k++)
        {
            printf("I I\t");

        }
        printf("\n");

    
    }
    return 0;
}

实验7: 如上图

 

标签:include,int,scanf,实验,printf,main,day
From: https://www.cnblogs.com/zcyy123/p/17224419.html

相关文章

  • 实验二
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验2
    实验任务1:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand(......
  • 跟烤冷面一起做SEO实验:开篇词
    我可怜的网站一切的起因都源于我去年年底创建的网站腐蚀脚本,既然建立了网站,总是希望有人看的,然而事实就是这么残酷,我的博客真的没有多少观众老爷捧场0.0这里我也不管我......
  • 带你全方面了解字节 A/B 实验的文化与工具
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 A/B测试是在相同的环境下,通过随机的抽样把对照组和控制组进行区分,并分别实行新......
  • 实验2
    task.1源码//task1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;i......
  • 实验2
    实验任务1实验代码#include<stdio.h>#include<time.h>#include<stdlib.h>#defineN5#defineR1586#defineR2701intmain(){ intnumber,i; srand......
  • 网络对抗 Exp1-逆向破解实验
    目录逆向及Bof基础实践目标实践内容实践思路BOF原理基础知识准备实验过程直接修改程序机器指令,改变程序执行流程通过构造输入参数,造成BOF攻击,改变程序执行流注入Shellcode......
  • 实验二
    任务一#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand(time(0));f......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sr......
  • 网络对抗实验一 逆向及Bof基础实践--20201313
    目录1逆向及Bof基础实践说明1.1实验内容1.2基础知识1.2.1NOP,JNE,JE,JMP,CMP汇编指令的机器码:1.2.2掌握反汇编与十六进制编程器2直接修改程序机器指令,改变程序......