【20170926】C语言每日一练

【程序4】
题目:输入某年某月某日,判断这一天是这一年的第几天?

#include 

int main(int argc, char* argv[])
{
    int year,month,date;
    int sum = 0;
    int month2;
    printf("请输入年份:");
    scanf("%d",&year);
    printf("请输入月份:");
    scanf("%d",&month);
    printf("请输入日期:");
    scanf("%d",&date);

    if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
    {
        month2 = 29;
    }
    else
    {
        month2 = 28;
    }

    switch(month)
    {
        case 1:
            sum = date;
            break;
        case 3:
            sum = 31 + month2 + date;
            break;
        case 4:
            sum = 62 + month2 + date;
            break;
        case 5:
            sum = 92 + month2 + date;
            break;
        case 6:
            sum = 123 + month2 + date;
            break;
        case 7:
            sum = 153 + month2 + date;
            break;
        case 8:
            sum = 184 + month2 + date;
            break;
        case 9:
            sum = 215 + month2 + date;
            break;
        case 10:
            sum = 245 + month2 + date;
            break;
        case 11:
            sum = 276 + month2 + date;
            break;
        case 12:
            sum = 286 + month2 + date;
            break;
    }


    printf("The sum is %d",sum);


}

运行结果:

【20170926】C语言每日一练_第1张图片

【程序5】
题目:输入三个整数x,y,z,请把这三个数由小到大输出。

#include 
void main(void)
{
    int x, y, z;
    printf("请输入x:");
    scanf("%d", &x);
    printf("请输入y:");
    scanf("%d", &y);
    printf("请输入z:");
    scanf("%d", &z);

    int min = x;
    if (x > y)
    {
        min = y;
        y = x;
        x = min;

    }
    if (x > z)
    {
        min = x;
        x = z;
        z = min;

    }
    if (y > z)
    {
        min = z;
        z = y;
        y = min;

    }

    printf("The sort queue is %d,%d,%d\n", x, y, z);

}

运行结果:

【20170926】C语言每日一练_第2张图片

【程序六】
用*输出C的图案


#include 
void main(void)
{
    printf("    ****\n");
    printf("  *\n");
    printf(" *\n");
    printf(" *\n");
    printf("  *\n");
    printf("    ****\n");

}

【20170926】C语言每日一练_第3张图片

**【程序8】
题目:输出9*9口诀。**

#include 

int main(int argc, char* argv[])
{
    int i,j;
    int count = 0;
    for(i = 1;i <= 9;i++)
    {
        for(j = 1; j <= 9; j++)
        {
            printf("%d\t",i*j);
            count++;
            if(count % 9==0)
            {
                printf("\n");
            }
        }
    } 
}

运行结果:

【20170926】C语言每日一练_第4张图片

你可能感兴趣的:(C语言经典100例)