I’m trying to make a function which help to find largest number.
But it’s not work properly.If i input gradually 2 5 6 8 then output is 8;That’s mean Right!
But if i input 2 8 6 5 then output is 5;That’s mean function is not work properly.
where i did mistake
Can you help me please to figure that out
Here is my code-
#include <stdio.h>
int max_of_four(int a,int b, int c, int d)
{
int largest;
if(a >= b && a >= c && a >= d);
largest = a;
if(b >= a && b >= c && b >= d);
largest = b;
if(c >= a && c >= b && c >= d);
largest = c;
if(d >= a && d >= b && d >= c);
largest = d;
return largest;
}
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;
}