I need help in this code, it gives me wrong out put, please fix it

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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;
     }

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education