C Programming Tutorial

 
 
 
 
   void sort(int m, int x[ ]);                                                               
   main()                                                      
   {                                                           
       int i;                                                  
       int marks[5] = {40, 90, 73, 81, 35};             

       printf(\"Marks before sorting\\n\");                       
       for(i = 0; i < 5; i++)                                  
          printf(\"%d \", marks[i]);                             
       printf(\"\\n\\n\");                                         

       sort (5, marks);                                        
       printf(\"Marks after sorting\\n\");                        
       for(i = 0; i < 5; i++)                                  
          printf(\"%4d\", marks[i]);                             
       printf(\"\\n\");                                           
   }                                                           
   void sort(int m, int x[ ])
   {                                                           
       int i, j, t;                                            

       for(i = 1; i <= m-1; i++)                               
          for(j = 1; j <= m-i; j++)                             
             if(x[j-1] >= x[j])                                
             {
                t = x[j-1];                                    
                x[j-1] = x[j];                                 
                x[j] = t;                                      
             }                                                 
   }                                                           
                                                                Output                                                      
           Marks before sorting                                        
           40 90 73 81 35                                              

           Marks after sorting                                         
             35  40  73  81  90                                        

    Related Post:
  1. Program for count number of digits in string

  2. PROGRAM TO READ NUMBERS, N1 AND N2 ARE INTERCHANGE WITHOUT USING EXTRA VARIABLES.N1=10, N2=20 THEN O/P IS N1=20, N2=10 USING MULTIPLICATION, DIVISION

  3. Program to search and/or replace a word in C Program

  4. Program to get substring of entered text or word by taking starting index and number of characters from a user

  5. Program that displays floyds triangle of numbers

  6. Program to display triangle

  7. PROGRAM THAT PROVIDES THE USE OF SHORTHAND OPERATOR *=

  8. Program to read two positive numbers and interchange its values using +(add) and -(sub) operators and without using any extra variable

  9. Example 7 of using function

  10. PROGRAM THAT CHECK WHETHER THE GIVEN NUMBER IS PRIME IN PARALLEL

  11. Program to compute x to the power n using while loop

  12. Program to sort a list in alphabatic order using pointers

  13. PROGRAM THAT WILL PRINT YOUR MAILING ADDRESS IN THE FOLLOWING FORM: FIRSTLINE:- NAME, SECOND LINE:-DOOR NO. STREET, THIRD LINE:-PIN CODE

  14. PROGRAM TO PERFORM THE AND GATE

  15. Program to transpose a sparse matrix

  16. Program that takes a number from user and calculates its logarithm value to the base 10 and e, exponentiation, sin value, cosine value and square root

  17. Straight-line method of computing the yearly depreciation of the value of an item i.e DEPREATION = (PURCHASE VALUE - SALVAGE VALUE) / YEAR OF SERVICE

  18. Program to create a singly linked list of numbers using threads

  19. Program to swap elements of array of pointers to strings

  20. Program to illustrate one-dimensional array

 
 
Didn't find what you were looking for? Find more on Sorting of array elements using a function