Thread: function to sort array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2022
    Posts
    96

    function to sort array

    Hi,
    I have written code to sort array numbers in increasing order

    Code:
    #include <stdio.h>
    
    int main()
    {
       int i = 0;
       int j = 0;
       int temp;
       
       int array[5] = { 50, 40, 30, 20, 10}; 
       
       for ( i = 0; i < 5; i++)
       {
    	    for ( j = i + 1; j < 5; j++)
    		{
    			temp = array[i];
    			array[i] = array[j];
    			array[j] = temp;   
    		}
       
       }
       
       for ( i = 0; i < 5; i++)
       {
    	   printf(" %d ", array[i]);
       }
       
       
     
        return 0;
    
    }



    I am now trying to make a function to sort array in increasing order

    Code:
    #include <stdio.h>
    
    void foo ( int *ptr)
    {
    	// How to sort array in increasing order in function
    	
    }
    
    
    int main()
    {
       int i = 0;
       int j = 0;
       int temp;
       
       int array[5] = { 50, 40, 30, 20, 10}; 
       
       foo(&array[0]);
       
       // print array after calling function
       for ( i = 0; i < 5; i++)
       {
    	   printf(" %d ", array[i]);
       }
       
     
        return 0;
    
    }


    I am looking help to make function so how to make function that sort array in increasing order
    Last edited by Kittu20; 01-20-2023 at 08:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sort array by function to get Max number.help plz
    By ILight in forum C Programming
    Replies: 11
    Last Post: 03-20-2015, 07:39 PM
  2. Replies: 4
    Last Post: 11-14-2012, 09:14 PM
  3. Replies: 1
    Last Post: 07-30-2011, 12:49 PM
  4. Replies: 1
    Last Post: 01-26-2010, 09:02 AM
  5. Replies: 4
    Last Post: 12-06-2009, 12:27 PM

Tags for this Thread