首页 > 其他分享 >实验二

实验二

时间:2024-04-15 14:11:41浏览次数:16  
标签:3405472 int blog 实验 printf include com

TASK 1

点击查看代码
#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() % 65 + 1;
        printf("20238331%04d\n", number);
    }
    return 0;
}
![](/i/l/?n=24&i=blog/3405472/202404/3405472-20240415135155554-2142151837.png) TASK 2
点击查看代码
#include <stdio.h>
int main()
{
	char colour;
	printf("请输入交通信号灯的颜色:");
	while ((colour = getchar()) != EOF)
	{
		switch (colour)
		{
		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");
		}
		getchar();
	}
	return 0;
}
![](/i/l/?n=24&i=blog/3405472/202404/3405472-20240415135536538-588891064.png) TASK 3
点击查看代码
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int main() {
    int number, m, i;
    srand(time(0));
    printf("猜猜2024年5月哪一天会是你的lucky day");
    number = rand() % 30 + 1;
    printf("\n");
    printf("开始喽,你有三次机会,猜吧(1~31):");
    scanf_s("%d", &m);
    for (i = 0; i < 2; ++i)
    {
        if (m > number)
        {
            printf("你猜的日期晚了,你的lucky day在前面哦\n再猜(1~31):");
            scanf_s("%d", &m);
        }
        else if (m < number)
        {
            printf("你猜的日期早了,你的lucky day还没到呢\n再猜(1~31):");
            scanf_s("%d", &m);
        }
        else
        {
            printf("哇,猜中了:-)");
            break;
        }
    }
    if (i == 2)
        printf("次数用完啦。偷偷告诉你,5月你的lucky day是%d", number);
    return 0;
}
![](/i/l/?n=24&i=blog/3405472/202404/3405472-20240415135839529-327845756.png) TASK 4
点击查看代码
#include<stdio.h>
 int main()
 {
	 int n, a, i, up, down;
	 double s, ans;
	 ans = 0;
	 printf("请输入正整数n和a:");
	 while (scanf_s("%d %d", &n, &a) != EOF)
		 {
		 for (i = 1, s = 0, down = 0; i <= n; i++)
			 {
			     up = i;
			     down = down * 10 + a;
			     ans = up * 1.0 / down;
			     s = s + ans;
			  }
		  printf("n=%d,a=%d,s=%f", n, a, s);
	 printf("\n请输入正整数n和a:"); }
 return 0;
 }

![](/i/l/?n=24&i=blog/3405472/202404/3405472-20240415140243836-479049533.png) TASK 5
点击查看代码
![](/i/l/?n=24&i=blog/3405472/202404/3405472-20240415140358685-888898226.png)

![](/i/l/?n=24&i=blog/3405472/202404/3405472-20240415140404770-1258603335.png) TASK 6
点击查看代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
int main() {
    int n, i, k, j;
    printf("input n:");
    scanf("%d", &n);

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

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

        for (j = 0; j < i; j++)
        {
            printf("\t");
        }
        for (k = 2 * (n - i) - 1; k > 0; k--)
        {
            printf("I I\t");
        }
        printf("\n");
    }
    system("pause");
    return 0;
}
![](/i/l/?n=24&i=blog/3405472/202404/3405472-20240415140757901-392903685.png) ![](/i/l/?n=24&i=blog/3405472/202404/3405472-20240415140802339-173813403.png)

标签:3405472,int,blog,实验,printf,include,com
From: https://www.cnblogs.com/minxzbc/p/18135792

相关文章

  • 实验2
    点击查看代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){ intnumber; inti; srand(time(0)); for(i=0;i<N;++i){ number=rand()%65+1; printf("20238331%04d\n",number); } ret......
  • 实验2
    task1`#include<stdio.h>include<stdlib.h>include<time.h>defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",number);}system("pa......
  • 实验二
    1#include<stdio.h>2#include<stdlib.h>3#include<time.h>456#defineN578intmain()9{1011intnumber;12inti;13srand(time(0));1415for(i=1;i<N;++i){16number=rand()%65+......
  • 易基因:ENCODE和modENCODE联盟的ChIP-seq实验设计指南和注意事项|干货
    大家好,这里是专注表观组学十余年,领跑多组学科研服务的易基因。ChIP-seq(染色质免疫沉淀测序)实验指南和实践(ChIP-seqguidelinesandpracticesoftheENCODEandmodENCODEconsortia),由ENCODE(EncyclopediaofDNAElements)和modENCODE(ModelOrganismENCODE)联盟研究人员撰写。文......
  • 实验2
    task11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN567intmain()8{9intnumber;10inti;1112srand(time(0));//以当前系统时间作为随机种子1314for(i=0;i<N;++i){15......
  • 实验2
    1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN567intmain()8{9intnumber;10inti;1112srand(time(0));1314for(i=0;i<N;++i){15number=rand()%......
  • 实验2
    任务11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN567intmain()8{9intnumber;10inti;1112srand(time(0));1314for(i=0;i<N;++i){15number=rand()%65......
  • 实验二
    1.实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",......
  • 实验2
    task1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%......
  • 实验2
    实验一#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",number......