实验2 C语言控制语句应用编程

#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);//随机生成一个2018到2021年,尾号在1到999之间的学号

    }
    return 0;
}

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

 

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

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

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

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {
        printf(" o \n");
        printf("<H>\n");
        printf("I I\n\n");
    }
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    int n,i,j;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {
        printf("  o  ");
        if (i == n)
        {
            printf("\n");
        }
    }
    for (i = 1; i <= n; i++)
    {
        printf(" <H> ");
        if (i == n)
        {
            printf("\n");
        }
    }
    for (i = 1; i <= n; i++)
    {
        printf(" I I ");
        if (i == n)
        {
            printf("\n");
        }
    }
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    int n,line,i,j,k,p,q,r;
    scanf("%d", &n);
    for (line = 1; line <= n; line++)
    {
        for (i = 1; i <= line - 1; i++)
        {
            printf("     ");
        }
        for (j = 1; j <= ((2 * n - 1) - 2 * (line - 1)); j++)
        {
            printf("  o  ");
            if (j == ((2 * n - 1) - 2 * (line - 1)))
            {
                printf("\n");
            }
        }
        for (k = 1; k <= line - 1; k++)
        {
            printf("     ");
        }
        for (p = 1; p<= ((2 * n - 1) - 2 * (line - 1)); p++)
        {
            printf(" <H> ");
            if (p == ((2 * n - 1) - 2 * (line - 1)))
            {
                printf("\n");
            }
        }
        for (q = 1; q <= line - 1;q++)
        {
            printf("     ");
        }
        for (r = 1; r <= ((2 * n - 1) - 2 * (line - 1)); r++)
        {
            printf(" I I ");
            if (r == ((2 * n - 1) - 2 * (line - 1)))
            {
                printf("\n");
            }
        }
    }
    return 0;
}

 

posted @ 2022-04-12 21:04  唐卉宁  阅读(16)  评论(2编辑  收藏  举报