首页 > 其他分享 >实验2

实验2

时间:2023-10-17 12:55:14浏览次数:34  
标签:include int colour number 实验 printf main

#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

 

这行代码的作用是生成一个N1到N2之间的随机整数,并将其存储在number变量中。

这个程序的主要目的是生成N个指定范围内的随机数,并按特定格式输出。运行该程序会输出5个形如"202383290376xxxx"的随机数,其中"xxxx"是具体的随机数值。

任务2:

#include<stdio.h>
int main()
{
	char colour;
	while(1)
	{
		scanf_s(" %c", &colour);
		if (colour == 'y')
			printf("wait a minute\n");
		else if (colour == 'g')
			printf("go go go\n");
		else if (colour == 'r')
			printf("stop!\n");
		else printf("samething must be wrong...\n");
			
	}
	return 0;
}

  

任务3:

 

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

  

 任务4:

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

  

 任务5:

#include<stdio.h>
int main() 
{
    int line, column;

    for (line = 1; line <=9; line++) 
    {
        for (column = 1; column <= line; column++) 
        {
            int result = line * column;
            printf("%d x %d = %2d  ", column, line, result);
        }
        printf("\n");
    }

    return 0;
}

  

 

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

  

 

标签:include,int,colour,number,实验,printf,main
From: https://www.cnblogs.com/daiyifei/p/17769437.html

相关文章

  • 实验二
    task1.c1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#defineN55#defineN13746#defineN24657intmain()8{9intnumber;10inti;11srand(time(0));//以当前系统时间作为随机种子12for(i=0;i<N;++i......
  • 实验2
    task11#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#defineN55#defineN13746#defineN24657intmain()8{9intnumber;10inti;11srand(time(0));//以当前系统时间作为随机种子12for(i=0;i<N;++i){......
  • 实验2
    #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......
  • 第二次实验
    任务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; printf("......
  • 实验二
    #include<stdio.h>#include<math.h>intmain(){intn,a,up,down,i=1;doubles;while(scanf("%d%d",&n,&a)==2){while(i<=n){up=i;down+=a*pow(10,i-1);s+=up*1.......
  • 实验二
    task1code1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#defineN55#defineN13746#defineN24657intmain()8{9intnumber;10inti;11srand(time(0));//以当前系统时间作为随机种子12for(i=......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1347#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%(N2-N1+1)+N1;......
  • 实验二
    实验二任务一代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain(){10intnumber;11inti;12srand(time(0));1314for(i=1;i<......
  • 实验二
    任务一t.h1#ifndefT_H2#defineT_H3#include<iostream>4#include<string>5usingnamespacestd;6classT7{8public:9T(intx=0,inty=0);10T(constT&t);11T(T&&t);12~T();13voidset_m1......
  • 实验二
    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;......