实验二

任务一

#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(); 500 % +1;
  printf("20228329%04d\n", number);
 }

 return 0;
}

 

 任务二

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

 

 任务三

#include<stdio.h>
#include<stdlib.h>
int main()
{
    char ans;
    while (scanf_s("%c", &ans, 1) != EOF)
    {
        getchar();
        switch (ans)
        {
        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;
}

 

 任务四

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

 

 任务五

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

 

 任务六

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

 

posted @ 2022-10-24 22:58  疙瘩宝  阅读(21)  评论(0)    收藏  举报