Biggest and smallest of four integers (No arrays, no functions, fewest 'if' statements)

后端 未结 18 2500
北海茫月
北海茫月 2020-12-10 11:29

You see, I\'ve self-taught myself C++ (not completely, I\'m still procrastinating -_-). So, now I started university and they\'re teaching C and they made us do a program of

18条回答
  •  -上瘾入骨i
    2020-12-10 11:47

    This is C code has only 4 if statements. It moves max number to d position and min number to a position. Values b and c are not properly arranged within a sequence, but since requirements ask for min and max this code completes a job:

    #include 
    
    
        int main() {
            int a, b, c, d, temp;
            printf("Enter four digits: ");
            scanf("%d %d %d %d", &a, &b, &c, &d);
            if ( a > b){
                temp = a; a = b ; b = temp;
            }
            if ( c > d){
                temp = c; c = d ; d = temp;
            }
            if ( b > d ){
                temp = b; b = d; d = temp;
            }
            if ( a > c){
                temp = a; a = c ; c = temp;
            }
            printf("Max %d\nMin %d\n", d, a);
    
            return 0;
        }
    

提交回复
热议问题