首页 > 其他分享 >实验二

实验二

时间:2022-10-25 12:22:29浏览次数:39  
标签:include int number 实验 printf main define

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

问题一:在1—500之间取一个数字且包括500

问题二:随机生成一串数字

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

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

    srand(time(0));
    number = rand() % 30 + 1;
    printf("猜猜那一天会是你的Lucky day\n");
    printf("开始喽,你有三次机会,猜吧(1~30):\n");
    for (i = 1; i <= 3; i++)
    {
        scanf("%d", &n);
        getchar();

        if (n == number)
        {
            printf("你猜中了");
            break;
        }
        if (n < number)
        {
            printf("你猜的日期早了,Lucky day还没到呢\n");
        }
        if (n > number)
        {
            printf("你猜的日期晚了,Lucky day已经过啦\n");
        }
        if (i == 3) {
            printf("次数用光啦,偷偷告诉你:11月,你的Lucky day是%3d号\n", number);
            break;
        }
        if (i <= 2) {
            printf("再猜:\n");
        }
    }


    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    char x;

    while (scanf(" %c", &x) != EOF)
    {
        switch (x)
        {
        case 'r':printf("stop\n"); break;
        case 'g':printf("gogogo\n"); break;
        case 'y':printf("wait a moment\n"); break;
        default:printf("something must be wrong \n");

        }

    }
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
    int n, a, b;
    double s, c;

    while (scanf_s("%d,%d", &n, &a) != EOF)
    {
        b = n;
        c = a;
        n = 1;

        for (s = 0; n <= b; ++n)
        {
            s = s + n / c;
            c = 10 * c + a;
        }
        printf("n=%d,a=%d,s=%f\n", b, a, s);
        printf("\n");
    }

    return 0;
}

#include<stdio.h>

int main()
{
    int a, b;
    for (a = 1; a <= 9; a++)
    {
            for (b = 1; b <= a; b++)
            printf("%dx%d=%2d ", b, a, a * b);
        printf("\n");
    }
}

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    int i, m, n;
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        for (m = 1; m < i; m++) {
            printf(" \t");
        }
        for (m = 1; m <= 2 * (n - i) + 1; m++) {
            printf(" O \t");
        }
        printf("\n");
        for (m = 1; m < i; m++) {
            printf(" \t");
        }
        for (m = 1; m <= 2 * (n - i) + 1; m++) {
            printf("<H>\t");
        }
        printf("\n");
        for (m = 1; m < i; m++) {
            printf(" \t");
        }
        for (m = 1; m <= 2 * (n - i) + 1; m++) {
            printf("I I\t");
        }
        printf("\n");
        printf("\n");
    }
    return 0;
}

 

标签:include,int,number,实验,printf,main,define
From: https://www.cnblogs.com/sjj66/p/16824447.html

相关文章

  • 实验7:基于REST API的SDN北向应用实践
    一、基本要求:①、编写Python程序,调用OpenDaylight的北向接口实现以下功能:1、删除s1上的流表数据代码及其截图:#!/usr/bin/pythonimportrequestsfromrequests.authim......
  • 实验2 C语言控制语句应用编程
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i)......
  • 实验二
    实验任务1task1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i......
  • 实验3
    实验任务五cpp#include<iostream>#include<string>#include<vector>#include<iomanip>#include"info.hpp"usingnamespacestd;intmain(){constint......
  • 实验7:基于REST API的SDN北向应用实践
    (一)基本要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能。    (1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight    (2)下发指令删除s1上......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践(一)基本要求1、编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;......
  • 实验7:基于REST API的SDN北向应用实践
    基础要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;下发指令删除s1上的流表数据#delet......
  • 实验3
    task5Info.h1#pragmaonce2#include<iostream>3#include<vector>4#include<string>5usingnamespacestd;67classinfo{8public:9in......
  • 实验7:基于REST API的SDN北向应用实践
    (一)基本要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能调用OpenDaylight的北向接口获取拓扑信息importrequestsasrqfromrequests.authimportHTTP......
  • 实验3 数组、指针与现代C++标准库
    实验任务5:info.hpp:#include<iostream>#include<string>usingnamespacestd;classinfo{public:info(stringni,stringco,stringci,intn);voidpri......