# finding maximum munber

• 03-25-2002
condorx
finding maximum munber
a=1 b=2 c=3
how can i find max,min numbers in c without using arrays just if statement
• 03-25-2002
Nit
Code:

``` int high, num, low = 0; while (test condition)     if (num > high)         high = num;     if (num < low)         low = num;     //grab next value of num from file, stdin, etc... }```
• 03-25-2002
condorx
but i have 3 munbers not 2
this function is works if i have 2 variables but i have 3 variables a,b,c
• 03-25-2002
Unregistered
but if one of the numbers is minus (-4)
so the LOW is not the low

if (a>b && a>C)
max = a;

else if (b>a && b>c)
max=b;
else max=c;
• 03-25-2002
condorx
my code doesnt work
#include <conio.h>
#include <stdio.h>
int a,b,c,max,min,av;

void main() {
clrscr();
printf("1.number:");
scanf("%d",&a);
printf("2.number:");
scanf("%d",&b);
printf("3.number:");
scanf("%d",&c);
//---------------------------- max number
if(a>b && a>c)
a=max;
else if(b>a && b>c)
b=max;
else
c=max;
//------------------------------- min number
if(a<b && a<c)
a=min;
else if(b<a && b<c)
b=min;
else
c=min;
//-----------------------------//between max and min
if(a==min && c==max || a==max && c==min)
b=av;
else if(b==min && c==max || b==max && c==min)
a=av;
else
c=av;

printf("max=\n",max);
printf("min=\n",min);
printf("av=\n",av);
getch();
}

what is wrong here??
• 03-25-2002
got it
here is the correct code

#include <conio.h>
#include <stdio.h>
int a,b,c,max,min,av;

void main() {
clrscr();
printf("1.number:");
scanf("%d",&a);
printf("2.number:");
scanf("%d",&b);
printf("3.number:");
scanf("%d",&c);
//---------------------------- max number
if(a>b && a>c)
max=a;
else if(b>a && b>c)
max=b;
else
max=c;
//------------------------------- min number
if(a<b && a<c)
min=a;
else if(b<a && b<c)
min=b;
else
min=c;
//-----------------------------//between max and min
if((a==min && c==max || a==max && c==min))
av=b;
else if((b==min && c==max )||( b==max && c==min))
av=a;
else
av=c;

printf("max=%d\n",max);
printf("min=%d\n",min);
printf("av=%d\n",av);
getch();
}

you made a mistake by assigning a=max ,as max at that moment contain no value so you are assigning a=0. and same is the case with av and min.

another mistake was the %d sign you did not put that in the last printf statements.