首页 > 其他分享 >实验2

实验2

时间:2023-10-16 20:23:43浏览次数:36  
标签:main int ++ 实验 printf include color

实验任务1

 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5
#define N1 374
#define N2 465

int main()
{
	system("color E5");
    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代码的功能:以当前系统时间作为随机种子,随机生成一个374~465的整数

问题2:这个程序的功能是什么:生成4个最后三位随机的数字,随机范围是374~465,前面固定为2023832903760

 

实验任务2

#include<stdio.h>
#include<stdlib.h>
int main(void)
{
	system ("color 6F");
	char col;
	while(scanf("%c",&col)!=EOF)
	{
	   switch(col)
	   {
		   case 'r':printf("stop!\n");break;
		   case 'g':printf("go go go\n");break;
		   case 'y':printf("wait a minute\n");break;
		   defualt :printf("something must be wrong...\n");
	   }
    }
    return 0;	
}

  

 

实验任务3

int main()
{
	system("color 5F");
    int shit;
    int i,j=0;
    int day;
    printf("猜猜2023年11月哪一天你会踩到狗屎\n");
    printf("开始喽,你有三次机会,猜吧(1~30):"); 
    srand( time(0) ); 
    shit = rand()%31;
    for(i=1;i<=3;i++)
    {
    	scanf("%d",&day);
    	if(day>shit)
    	{
    	   printf("你猜得晚了,你还踩不到狗屎呢\n");
    	   j++;
        }
		else if(day<shit)
		{
		   printf("你猜得早了,你已经踩过狗屎辣\n");
		   j++;
	    }
		else if(day=shit)
		{
		   printf("哇!踩到狗屎辣\n");
		   exit(0);
	    }
	    if(i<3)
	        printf("再猜:");
	    else if(j==3)
	       printf("次数用完辣,偷偷告诉你:11月,你在%d号会踩到狗屎",shit);
	}
    return 0;
}

 

实验任务4

 

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
	system("color 9F");
	int t=1;
	int i;
	int n,a;
	double s;
	while(scanf("%d %d",&n,&a)!=EOF)
	{
	    for (i=1;i<=n;i++)
        {
    	    s+=i/(t*a*1.0);
    	    t=t*10+1; 
	    }
	    printf("n = %d, a = %d, s = %lf\n\n",n,a,s);
    }
	return 0;
} 

  

 实验任务5

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

 实验任务6

#include<stdio.h>
#include<stdlib.h>
int main()
{
	system("color B5");
    int n;
    printf("input n:");
    scanf("%d", &n);
    int m = 2*n - 1;
    int max = m * 3 + ( m - 1) * 4; 
    for (int i = m ; i > 0; i -= 2) 
	{
        int width = i * 3 + (i - 1) * 4; 
        int fuck = (max - width) / 2;
        for (int j=0; j < fuck; j++) 
            printf(" ");
        for (int j = 0; j < i; j++) 
		{
            printf(" O ");
            if (j != i - 1)
                printf("    ");  
        }
        printf("\n");
        for (int j = 0; j < fuck; j++) 
            printf(" ");
        for (int j = 0; j < i; j++)
		{
            printf("<H>");
            if (j != i - 1) 
                printf("    "); 
        }
        printf("\n");
        for (int j = 0; j < fuck; j++)
            printf(" ");
        for (int j = 0; j < i; j++) 
		{
            printf("I I");
            if (j != i - 1) 
                printf("    "); 
        }
        printf("\n\n");
    }
    return 0;
}

 

标签:main,int,++,实验,printf,include,color
From: https://www.cnblogs.com/Obrez/p/17767933.html

相关文章

  • 实验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......
  • 实验2_C语言分支与循环基础应用编程
    1.task_11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;1314srand(time(0));1516for......
  • 实验2
    实验2task11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;1314srand(time(0));1516for(i......
  • 实验2
    实验2-11#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#include<math.h>56#defineN57#defineN13748#defineN2465910intmain()11{12intnumber;13inti;1415srand(time(0))......
  • 实验2
    #include<stdio.h>intmain(){charcolour;while(scanf("%c",&colour)!=EOF){if(colour>='a'&&colour<='z'){if(colour=='r'){prin......
  • 实验二
    一.实验任务一源码#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)+......
  • 实验二
    任务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;pri......
  • 实验二
    task1.c源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;1314srand(time(0));1516for(i=0;i......
  • 实验2
    task1line17功能是在(N2-N1+1)+N1之间随机选取一个数字代码功能是随机生成学号 task21#include<stdio.h>2intmain()3{4charcolour;56while(scanf("%c",&colour)!=EOF){7if(colour>='a'&&colour<=......