实验二实践任务

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
{
int a;
int b;
int n;

printf("猜猜2022年11月哪一天会是你的lucky day\n开始咯,你有三次机会,猜吧(1~30):");

a=rand()%31+1;
for(n=1;n<=3;n++){scanf("%d",&b);
if(n==3){
if(a>b)
printf("你猜的日期早了,你的lucky day还没到呢\n");
if(a<b)
printf("你猜的日期晚了,你的lucy day已经过啦\n");
if(a==b){
printf("哇,猜中了:-)");break;}break;
}

if(a>b)
printf("你猜的日期早了,你的lucky day还没到呢\n再猜(1~30):");
if(a<b)
printf("你猜的日期晚了,你的lucy day已经过啦\n再猜(1~30):");
if(a==b)
{
printf("哇,猜中了:-)");break;}
}

if(n=4)
printf("次数用完啦。偷偷告诉你:11月,你的lucky day是8号");

return 0;}

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
{
char n;
n = getchar();
while (scanf_s("%c", & n) != EOF)
{
switch (n) {
case'r':printf("stop!"); getchar(); break;

case'g':printf("go go go"); getchar(); break;

case'y':printf("wait a minute"); getchar(); break;

default:printf("something must be wrong..."); getchar(); break;
}
}


return 0;










}

#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>
int main()
{
    int a, n, i;
    double s, x1, x2;
    while (scanf_s("%d%d", &n, &a) != EOF) {
        x1 = 1;
        x2 = a;
        for (i = 1, s = 0; i <= n; i++) {
            s = s + x1 / x2;
            x1 = x1 + 1;
            x2 = x2 * 10 + x2;
        }
        printf("n=%d,a=%d,s=%.6f\n", n, a, s);
    }

    return 0;
}

#include<stdio.h>
int main()
{
    int line, a, s, i;
    a = 1;
    scanf_s("%d", &line);
    for (; a <= line; a++) {
        for (i = 1; i <= a; i++) {
            s = i * a;
            printf("%d*%d=%d\t", i, a, s);
        }
        printf("\n");
    }
    return 0;
}

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

需要2(n-i)+1个字符小人

需要打印i-1个tab

posted @ 2022-10-23 21:12  李龙圭  阅读(33)  评论(0)    收藏  举报