有3個整數a, b, c,由鍵盤輸入,輸出其中最大的數


有3個整數a, b, c,由鍵盤輸入,輸出其中最大的數。

解題思路: 每個數字兩兩與剩余兩個數字進行比較,若比剩下的兩個數大則最大,例如:a>b && a>c則a是最大的

答案:

#include <stdio.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a == b && a == c) {
        printf("Three numbers are equal\n");
    }else if (a == b && a > c) {
        printf("a and b are the largest number\n", a); 
    }else if (a == c && a > b) {
        printf("a and c are the largest number\n", a); 
    }else if (b == c && b > a) {
        printf("c and b are the largest number\n", a); 
    }else if (a > b && a > c) {
        printf("a=%d is the largest number\n", a); 
    }else if (b > a && b > c) {
        printf("b=%d is the largest number\n", b); 
    }else {
        printf("c=%d is the largest number\n", c); 
    }   
    return 0;
}

有3個整數a, b, c,由鍵盤輸入,輸出其中最大的數


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM