clm888

导航

实验2

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define N 5

int main()
{
    int grade, number;
    int i;

    srand(time(0)); // 以当前系统时间作为随机种子

    for (i = 0; i < N; ++i)
    {
        grade = rand() % 4 + 2018; //生成2018到2021之间的数
        number = rand() % 999 + 1; //生成1到999之间的数
        printf("%d8330%04d\n", grade, number);
    }

    return 0;
}//程序功能为随机生成五个201883300001到202183300999之间的学号

 

 

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

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

 

 

 

 

#include<stdio.h>
int main()
{
    char ch;
    while ((ch = getchar()) != EOF)
        if (ch == 'r')
            printf("stop!\n");
        else if (ch == 'y')
            printf("wait a minute\n");
        else if (ch == 'g')
            printf("go go go\n");
        else if (ch == '\n')
            ;
        else
            printf("something must be wrong...\n");
    return 0;
}

 

 

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

 

 

#include<stdio.h>
int main()
{
    int column, line,value;
    for (line = 1; line <= 9; line++)
    {
        for (column = 1; column <= line; column++)
        {
            value = line * column;
            printf("%d×%d=%d  ", column, line, value);
        }
        printf("\n");
    }
    return 0;
}

 

 

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

 

 

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

 

 

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

 

posted on 2022-04-12 16:52  clmmmmm  阅读(32)  评论(1编辑  收藏  举报