Thread: sorting array in increasing order

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2020
    Posts
    28

    sorting array in increasing order

    When we have

    list = 5 4 3 2 1

    how to sort array in increasing order ? list = 1 2 3 4 5

    here is process how I think

    5 - 4 compare if greater then update 4 5 3 2 1
    5 - 3 compare if greater then update 4 3 5 2 1
    5 - 2 compare if greater then update 4 3 2 5 1
    5 - 1 compare if greater then update 4 3 2 1 5

    and so more

    I wrote my program to sort array in increasing order


    Code:
    #include <stdio.h>
    
    int main()
    {
        int i = 0; int j = 0; int k = 0;
        
        int list[5] = {5, 4, 3, 2, 1};
        
        int temp[5];
        
        for (i = 0; i <5; i++)
        {
             for (j = i+1 ; j <5; j++)
             {
                 if (list[i]>list[j]) // if the one is greater then other swap value 
                 {
                     temp[k] = list[j];
                     list[i] = temp[k];
                     
                 }
             }
             
        }
        
        return 0;
    }
    What's wrong in code
    Last edited by Djsarkar; 08-02-2020 at 01:59 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help.. how to sort word in increasing order
    By cstyle in forum C Programming
    Replies: 6
    Last Post: 03-07-2017, 04:49 AM
  2. Flowchart - three numbers in increasing order
    By Dontknowtbh in forum C Programming
    Replies: 1
    Last Post: 09-02-2016, 12:22 PM
  3. Increasing order of integers
    By Mentallic in forum C Programming
    Replies: 3
    Last Post: 03-21-2010, 07:41 AM
  4. Sorting exam score in increasing order
    By superman12 in forum C Programming
    Replies: 5
    Last Post: 07-14-2005, 12:34 AM
  5. Replies: 2
    Last Post: 03-07-2002, 10:14 AM

Tags for this Thread