首页 > 其他分享 >实验2

实验2

时间:2023-10-16 22:57:48浏览次数:37  
标签:main CRT int 实验 printf include define

#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:生成一个374-465之间的随机数

实验问题2:该程序的功能是生成一个前面12位数列相同的16位数字

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>*/

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




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

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

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

int main() {
    double n, a;
    while (scanf("%lf%lf", &n, &a) != EOF) {
        double sum=0.0,x=a;

        for (int i = 1; i <= n; i++) {
            sum += i/x;
            x = x * 10 + a;
        }
        printf("n=%.0f,a=%.0f,s=%.6f\n", n, a, sum);
    }

}

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

int main() {
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= i; j++) {
            printf("%d*%d =%3d  ", j, i, i * j);
        }
        printf("\n");
    }
}

 

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


int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        for (int i = 1; i <=n; i++) {
            for (int j = 1; j < i; j++) {
                printf("\t");
            }
            for (int j = 1; j <= 2 * (n-i+1) - 1; j++) {
                printf(" O  \t");
            }
            printf("\n");
            for (int j = 1; j < i; j++) {
                printf("\t");
            }
            for (int j = 1; j <= 2 * (n - i + 1) - 1; j++) {
                printf("<H> \t");
            }
            printf("\n");
            for (int j = 1; j < i; j++) {
                printf("\t");
            }
            for (int j = 1; j <= 2 * (n - i + 1) - 1; j++) {
                printf("I I \t");
            }
            printf("\n");

        }
    }
}

 

标签:main,CRT,int,实验,printf,include,define
From: https://www.cnblogs.com/1118z105/p/17768571.html

相关文章

  • 实验2
    task1问题一:line17作用:限制随机数范围在374~465之间问题二:程序功能:随时间变化,随机生成在202383290376374~202383290376465之间的数task21#include<stdio.h>2intmain(){3chara;4while(1){5a=getchar();6getchar();7if(a==EOF){8......
  • 实验1 类和对象_基础编程
    实验任务11.代码:1#include<iostream>2#include<string>3#include<vector>4#include<array>567//函数模板8//对满足特定条件的序列类型T对象,使用范围for输出9template<typenameT>10voidoutput1(constT&obj){11for(autoi:obj)......
  • 实验2
    实验2.1实验2.1代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=1;i<N;++i){number=rand()%(N2-N1+1)+......
  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%(N2-N1+1)+N1;//计算num的值printf("......
  • 实验2
    task1代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain(){10intnumber,i;1112srand(time(0));1314for(i=0;i<N;++i......
  • 实验二 c语言分支与循环基础应用编程
    实验一源代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){ intnumber; inti; srand(time(0)); for(i=0;i<N;i++) { number=rand()%(N2-N1+1)+N1; printf("20238329%04......
  • 实验二
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%(N2-N1+......
  • 实验2
    实验任务1 #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){ system("colorE5");intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(i=0;i&......
  • 实验2 C语言分支与循环基础应用编程
    一、实验目的能正确使用if语句、switch语句实现分支结构能正确使用while语句、do...while语句、for语句实现循环结构能在具体问题场景中使用嵌套分支语句和嵌套循环语句能在具体问题场景中正确区分、使用continue和break能灵活、组合使用c语句编程解决简单应用问题二、实......
  • 实验2 C语言分支与循环基础应用编程
    练习1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(i=0;i<N;++i){number=rand()%(N2-N1......