Hey y'all. I think I've gotten it down a bit okay. I'm still working on Part A (Finding min and max numbers), but it's not working completely yet.
Code:
#include <stdio.h>
#include <math.h>
int maximum(int a, int b, int c, int d);
int minimum(int a, int b, int c, int d);
int main(void)
{
int a, b, c, d;
double m, M;
printf("Enter four integers: ");
scanf("%d %d %d %d", &a, &b, &c, &d);
M = maximum(a,b,c,d);
m = minimum(a,b,c,d);
printf("\nMaximum of a,b,c,d is: M=%d\n", M);
printf("\nMinimum of a,b,c,d is: m =%d\n\n", m);
}
int maximum(int a, int b, int c, int d)
{
int M;
if(a>b && a>c && a>d)
return a;
else if(b>a && b>c && b>d)
return b;
else if(c>a && c>b && c>d)
return c;
else if(d>a && d>b && d>c)
return d;
}
int minimum(int a, int b, int c, int d)
{
int m;
if (a<b && a<c && a<d)
return a;
else if (b<a && b<c && b<d)
return b;
else if (c<a && c<b && c<d)
return c;
else if (d<a && d<b && d<c)
return d;
}
I get that M and m are some number over 100,000,000 when my integers are "1 2 3 4". What's going on?