C语言学习(4)

版权声明:转载请注明出处:http://blog.csdn.net/liu6886 https://blog.csdn.net/liu6886/article/details/80006181

条件判断

if-else

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

int main()
{
    int a, b;
    a = 10;
    b = 15;
    if (a > b)//切记括号不能再加 ;号
    {
        printf("a is bigger\n");
    }
    else{
        printf("b is bigger\n");
    }
    system("pause");
    return 0;
}

switch

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

//输入一个月份, 输出该月份有多少天
int main()
{
    int mon;
    while (scanf("%d", &mon) != EOF)
    {
        switch (mon)
        {
        case 1:
        case 3:
        case 5: 
        case 7:
        case 8:
        case 10:
        case 12:printf("month %d is 31 days\n", mon); break;
        case 4:
        case 6:
        case 9:
        case 11:printf("month %d is 30 days\n", mon); break;
        case 2:printf("month %d is 28 days\n", mon); break;
        default:printf("month error\n");
        }
    }
    system("pause");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/liu6886/article/details/80006181