ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

实验二

2022-04-18 20:01:14  阅读:33  来源: 互联网

标签:ld include int scanf 实验 printf main


实验二

task1

#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;
        number=rand()%999+1;
        printf("%d8330%04d\n",grade,number);
    }
    return 0;
}

image

task2

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 3
int main()
{
    int ld, d,i,n=0;
    srand(time(0));
    ld = rand() % 30 + 1;

    printf("猜猜2022年4月哪一天会是你的lucky day\n\n");
    printf("开始喽,你有三次机会,猜吧(1^30):");
    for (i = 0; i < N; ++i)
    {
        scanf_s("%d", &d);
        if (d == ld)
        {
        printf("\n哇,猜中了:-)\n"); break;
        }

        if (d > ld)
        {
            printf("\n你猜的日期晚了,你的lucky day已经过啦\n");
        }
        else
        {
            printf("\n你猜的日期早了,你的lucky day 还没到呢\n");
        }
        n++;

        if(n<N)
        {
            printf("\n再猜(1^30):");
        }
        else
        {
            printf("\n次数用完啦。偷偷告诉你:4月,你的lucky day是%d号\n", ld);
        }

    }
    return 0;
}

image

task3

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

image

task4

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

image

task5

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

image

task6_1.cpp

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

image

task6_2.cpp

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int i,n,j,k;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        printf(" o \t");

    printf("\n");

    for(j=1;j<=n;j++)
       printf("<H> \t");

    printf("\n");

    for(k=1;k<=n;k++)
        printf("I I \t");

    printf("\n");
    return 0;
}

image

task6_3.cpp

#include <stdio.h>
int main()
{
    int n, i, j;
    printf("input n:");
    scanf("%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("l l\t");
        }
        printf("\n");
    }
    return 0;
}

image

标签:ld,include,int,scanf,实验,printf,main
来源: https://www.cnblogs.com/wjjjjprincess/p/16161848.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有