Jan 25, 2022

Calculating Maximum out of four numbers (C Language)

 Using if condition  and Relational and Logical Operators.

#include<stdio.h>

int max_of_four(int a, int b, int c, int d)
{
    if(a>b && a>c && a>d){
        return a;
    }
    if(b>a && b>c && b>d){
        return b;
    }
    if(c>b && a<c && c>d){
        return c;
    }
    return d;
}
int main()
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int ans = max_of_four(a, b, c, d);
    printf("%d", ans);

    return 0;
}

No comments:

Post a Comment

Comparing two files in C language.

Operations on More than one File.    # include < stdio.h > # include < stdlib.h > # include < string.h > int main ( int ...