I need help in this code, it gives me wrong out put, please fix it
I need help in this code, it gives me wrong out put, please fix it
#include <stdio.h>
int main ()
{
// declaring variables
int N1, N2 ,N3,N4,N5;
int maximum, max1, max2, max3;
int minimum, min1, min2, min3;
int i,j,m;
int num[100],n=5;
// asking the user to enter the 4 number
printf("please enter first number:\n ");
scanf("%d",&N1);
printf("please enter second number:\n ");
scanf("%d",&N2);
printf("please enter third number :\n ");
scanf("%d",&N3);
printf("please enter fourth number :\n");
scanf("%d",&N4);
printf("please enter fifth number :\n ");
scanf("%d",&N5);
/* divide the 5 numbers*/
if (N1>N2)
{
max1 = N1;
}
else
max1 = N2;
if (N3>N4)
{
max2 = N3;
}
else
max2 = N4;
if (N4>N5)
{
max3 = N4;
}
else
max3 = N5;
// check the maximum of each group//
if (max1 > max2)
{
maximum = max1;
}
else
maximum = max2;
if (max2>max3)
{
maximum = max2;
}
else
maximum = max3;
printf("maximum = %d\n", maximum);
// check the minimum of each max groups//
if(N1<N2)
{
min1 = N1;
}
else
min2 = N2;
if (N3<N4)
{
min2 = N3;
}
else
min2 = N4;
if (N4<N5)
{
min3 = N4;
}
else
min3 = N5;
if (min1 < min2)
{
minimum = min1;
}
else
minimum = min2;
if (min2 < min3)
{
minimum = min2;
}
else
minimum = min3;
printf("minimum = %d \n", minimum); // print the minimum number
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if ( num [i]< num[j])
{
m = num[i];
num[i] = num[j];
num[j] = m;
}
}
}
printf("Ascending: \n"); // the number that the user entered will be ascending
for (i=0;i<n;i++)
{
printf("%d\n", num[i]);
}
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
if (num[i]>num[j])
{
m=num[i];
num[i]=num[j];
num[j]=m;
}
}
}
printf(" Descending:\n"); // the number that the user entered will be descending
for(i=0;i<n;i++)
{
printf("%d\n",num[i]);
}
return 0;
}
Step by step
Solved in 2 steps