首页 > 其他分享 >实验2

实验2

时间:2023-10-22 23:57:20浏览次数:21  
标签:include 源代码 int 实验 printf main

实验1源代码

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

实验1运行结果

line17意义:使生成375到465之间的一个随机数

实验2源代码

 

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

int main()
{
    char color;
    while (scanf("%c", &color) != EOF)
    {
        getchar();
        switch (color)
        {
        case'r':
            printf("stop\n");
            break;

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

        case'y':
            printf("wait a minute\n");
            break;

        default:
            printf("something must be wrong\n");
            break;

        }
    }
        return 0;
}

实验2运行结果

实验3源代码

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


    
}

实验3运行结果

实验4源代码

 

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

    printf("n = %d,a = %d,s = %lf\n", n, a, s);
    }
}

实验4运行结果

实验5源代码

#include<stdio.h>
int main() {
    int i, n, p;
    for (i = 1; i <= 9; ++i)
    {
        for (p = 1; p <= i; ++p)
        {
            n = i * p;
            printf("%4d*%d=%3d",i,p,n);

        }
        printf("\n");

    }

}

实验5运行结果

实验6源代码

#include <stdio.h>
#include <stdlib.h>
int main() {
    int n, i, m;
    i = 0;
    m = 0;
    scanf("%d", &n);
    while (n > 0)
    {
        for (i = 0; i < m; i++)
        {
            printf("      ");
        }
        for (i = 0; i <= 2 * (n - 1); i++)
        {
            printf(" o    ");
        }

        printf("\n");

        for (i = 0; i < m; i++)
        {
            printf("      ");
        }

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

        for (i = 0; i < m; i++)
        {
            printf("      ");
        }

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

        n--;
        m++;
    }
    return 0;
}

实验6运行结果

 

标签:include,源代码,int,实验,printf,main
From: https://www.cnblogs.com/wyf827/p/17767926.html

相关文章

  • 实验2
    任务1#ifndefT_H#defineT_H#include<iostream>#include<string>usingnamespacestd;classT{public:T(intx=0,inty=0);T(constT&t);T(T&&t);~T();voidset_m1(intx);intget_m1()const;intget_m2()co......
  • 实验2
    3.c.hpp#include<iostream>#include<cmath>classComplex{public:Complex(doubler=0,doublei=0);Complex(constComplex&c);doubleget_real()const;doubleget_imag()const;voidshow()const;voidadd(const......
  • 实验二 类和对象
    实验任务三1#include<iostream>2#include<cmath>34classComplex{56private:7doublereal;8doubleimag;910public:11Complex(doubler=0,doublei=0){12real=r;13imag=i;14}15......
  • 实验二
    任务三:complex.hpp代码:#include<iostream>#include<cmath>classComplex{public:Complex(doubler=0,doublei=0){real=r;imag=i;};Complex(constComplex&c){real=c.real;imag=c.imag;};~Complex(){};doubleget_real()const{returnreal......
  • 实验2 类和对象
    实验任务3t.hpp#pragmaonce#include<iostream>#include<cmath>usingnamespacestd;classComplex{public:Complex();Complex(doublereal0);Complex(doublereal0,doubleimag0);Complex(constComplex&x);doub......
  • 实验二 类与对象
    实验任务3complex.hpp#pragmaonce#include<iostream>#include<string>usingnamespacestd;classUser{public:User(std::stringname,std::stringpasswd="111111",std::stringemail=""):name{name},p......
  • 实验2 类和对象_基础编程2
    //第一个任务简单Complex类#pragmaonce#include<iostream>#include<cmath>classComplex{public:Complex(doublex0=0,doubley0=0);//构造函数Complex(constComplex&c);//拷贝构造函数~Complex(){};//析构函数doubleget_real()con......
  • 北京电子科技学院(BESTI)实验报告
    实验报告课程:计算机基础与程序设计班级:2314姓名:高伟光学号:20231404成绩:指导教师:娄佳鹏实验日期:2022.9.26实验密级:预习程度:部分预习实验时间:34节仪器组次:无必修/选修:必修实验序号:实验一实验名称:Li......
  • 实验二
    task.3.hpp#pragmaonce#include<iostream>#include<cmath>classComplex{public:Complex(doubler=0,doublei=0){real=r;imag=i;}Complex(constComplex&x){real=x.real;imag=x.imag;......
  • 实验二
    试验任务三complex.hpp点击查看代码#pragmaonce#include<iostream>#include<cmath>classComplex{public:Complex(doubler=0,doublei=0){real=r;imag=i;}Complex(constComplex&x){real=x.real;imag=x.i......