zoukankan      html  css  js  c++  java
  • (使用if-else述句)对多个变数求最大值的练习

    #include <stdio.h>
    int main()
    {
        int a,b,c,max;
        printf("Please enter three integers: ");
        scanf("%d%d%d",&a,&b,&c);
        if (a >= b && a >= c)
        {
            max = a;
        }else if (b >= a && b >= c)
        {
            max = b;
        } else {
            max = c;
        }
        printf("The maximum ids %d.", max);
        return 0;
    }

     switch 述句

    switch (整数值)  {
        case 常数整数值:
             程式片段;
             break;
        default:
             程式片段;
             break;
    
    }

    如:

    #include <stdio.h>
    int main()
    {
        int id;
        printf("ID: ");
        scanf("%d",&id);
        switch (id)
        {
        case 2:
            printf("John
    ");
            break;
        case 13:
            printf("Mary
    ");
            break;
        default:
            printf("Not found
    ");
            break;
        }
        return 0;
    
    
    }

     练习:消费金额计算的练习(使用switch述句)

    #include <stdio.h>
    int main()
    {
        int total = 0;
        int id;
        do{
                scanf("%d", &id);
        switch (id) {
            case 1: total += 90; break;
            case 2: total += 75; break;
            case 3: total += 83; break;
            case 4: total += 89; break;
            case 5: total += 71; break;
    
        }
            }while (id != 0);
            printf("Total: %d
    ", total);
            return 0;
    
    
    }
  • 相关阅读:
    Pyton项目打包成exe文件
    App数据指标
    电商基础指标体系
    Matplotlib复杂作图
    Sklearn之聚类分析
    Seaborn可视化
    Matplotlib可视化2
    Matplotlib可视化1
    Pandas可视化
    Linux常用指令(3)
  • 原文地址:https://www.cnblogs.com/pxxfxxxx/p/10711851.html
Copyright © 2011-2022 走看看