首页 > 其他分享 >实验2

实验2

时间:2022-10-24 21:34:41浏览次数:34  
标签:include int 实验 printf main getchar

实验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() % 500 + 1;
        printf("20228329%04d\n", number);
    }
    return 0;
}

 

实验2

 

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    int x, y, i;
    printf("猜猜2022年11月哪一天会是你的lucky day\n");
    printf("开始喽,你有三次机会,猜吧(1-30):");
    srand(time(0));
    y = rand() % 30 + 1;
    for (i = 1; i <= 3; ++i)
    {
        if (i <= 3)
        {
            scanf_s("%d", &x);
            if (x == y)
            {
                printf("哇,猜中了:-)"); break;
            }
            else if (x > y)
            {
                printf("你猜的日期晚了,你的lucky day 已经过啦\n");
                if (i <= 2)
                    printf("再猜(1-30):");
            }
            else if (x < y)
            {
                printf("你猜的日期早了,你的lucky day还没到呢\n");
                if (i <= 2)
                    printf("再猜(1-30):");
            }
        }
    }
    printf("\n次数用完了。偷偷告诉你:11月,你的lukcy day是%d号", y);
    return 0;
}

 实验3

#include<stdio.h>
#include<stdlib.h>
int main()
{
    char colour;
    while(scanf("%c",&colour)!=EOF)
    {
    switch(colour)
    {
     case 'y':printf("wait a minute\n");getchar();break;
     case 'g':printf("go go go\n");getchar();break;
     case 'r':printf("stop\n");getchar();break;
     default:printf("something must be wrong\n");getchar();break; 
     }

    }
     return 0;
}

实验4

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

实验5

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

实验6

 

#include<stdio.h>
int main()
{
    int i, j, k, n;
    printf("input n;");
    scanf_s("%d", &n);
    for (i = 1; i <= n; i++)
    {
        for (j = 0; j < i - 1; j++)
        {
            printf("\t");
        }
        for (k = 0; k < 2 * (n - i) + 1; k++)

        {
            printf(" o \t");
        }printf("\n");

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

        {
            printf("<H>\t");
        }printf("\n");

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

        {
            printf("I I\t");
        }printf("\n");

    }
    return 0;
}

 

标签:include,int,实验,printf,main,getchar
From: https://www.cnblogs.com/yaj030820/p/16804933.html

相关文章

  • 实验7:基于REST API的SDN北向应用实践
    (一)基本要求编写Python程序,调用OpenDaylight的北向接口实现以下功能。(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight。(2)下发指令删除s1上的流表数据#!/us......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0,i<N,i++)......
  • 实验5:开源控制器实践——POX
    一、实验目的1.能够理解POX控制器的工作原理;2.通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;3.能够运用POX控制器编写自定......
  • 实验7:基于REST API的SDN北向应用实践
    (一)基本要求编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)下发指令删除s1上的流表数据。import......
  • 实验3
    task51#include<iostream>2#include<vector>3#include<string>4#include<iomanip>5usingnamespacestd;6classInfo{7friendvoidprint(vect......
  • 实验一:决策树算法实验
    博客班级https://edu.cnblogs.com/campus/czu/classof2020BigDataClass3-MachineLearning作业要求https://edu.cnblogs.com/campus/czu/classof2020BigDataClass......
  • 实验二
    test1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){......
  • 实验5:开源控制器实践——POX
    (一)基本要求1.搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)sudomn--topo=single,3--mac--controller=remote,ip=127.0.0.1,......
  • 实验三
    实验3数组、指针与现代c++标准库一、task51.源代码:(1)Info.cpp#include<iostream>#include<string>#include<iomanip>usingnamespacestd;classinfo{public:......
  • 对多分类任务中的模型评估隐藏层层数和隐藏单元个数对实验结果的影响
    8、对多分类任务中的模型评估隐藏层层数和隐藏单元个数对实验结果的影响1.确定隐藏层的层数对于一些很简单的数据集,一层甚至两层隐藏元都已经够了,隐藏层的层数不一定设置......