sorting in c

Solutions on MaxInterview for sorting in c by the best coders in the world

showing results for - "sorting in c"
Damien
20 Jan 2020
1#include<stdio.h>
2int main(){
3   /* Here i & j for loop counters, temp for swapping,
4    * count for total number of elements, number[] to
5    * store the input numbers in array. You can increase
6    * or decrease the size of number array as per requirement
7    */
8   int i, j, count, temp, number[25];
9
10   printf("How many numbers u are going to enter?: ");
11   scanf("%d",&count);
12
13   printf("Enter %d elements: ", count);
14   // Loop to get the elements stored in array
15   for(i=0;i<count;i++)
16      scanf("%d",&number[i]);
17 
18   // Logic of selection sort algorithm
19   for(i=0;i<count;i++){
20      for(j=i+1;j<count;j++){
21         if(number[i]>number[j]){
22            temp=number[i];
23            number[i]=number[j];
24            number[j]=temp;
25         }
26      }
27   }
28
29   printf("Sorted elements: ");
30   for(i=0;i<count;i++)
31      printf(" %d",number[i]);
32
33   return 0;
34}
Ellen
06 Apr 2020
1#include <stdio.h>
2int main()
3{
4
5     int ara[1000];
6     int high;
7     printf("How many numbers are you going to enter ? (max:1000) : ");
8     scanf("%d", &high);
9     int i, j, min;
10     printf("\n");
11     for (i = 0; i < high; i++)
12     {
13          printf("Type number : ");
14          scanf("%d", &ara[i]);
15     }
16     printf("\n The numbers arranged in ascending order are : \n");
17     for (i = 0; i < high; i++)
18     {
19          for (j = i; j < high; j++)
20          {
21               if (ara[i] > ara[j])
22               {
23                    min = ara[i];
24                    ara[i] = ara[j];
25                    ara[j] = min;
26               }
27          }
28          // The numbers arranged in ascending order are
29          printf("%d\n", ara[i]);
30     }
31     return 0;
32}
Lina
19 Jul 2020
1for (int i = 0; i < arr.length; i++) {
2   for (int j = 0; j < arr.length-1-i; j++) { 
3     if(arr[j]>arr[j+1])
4     {
5       int temp=arr[j];
6       arr[j]=arr[j+1];
7       arr[j+1]=temp;
8     }
9   }
10   System.out.print("Iteration "+(i+1)+": ");
11   printArray(arr);
12  }
13  return arr;
14// BUBBLE SORT
Lucia
20 May 2017
1#include <stdio.h>
2
3int main()
4{
5    int ara[10]={4,45,23,53,2,64,56,34,77,98};
6    int i,j,temp;
7    for(i = 0; i < 10; i++){
8        
9        for(j = 0; j< 10; j++){
10            if(ara[i] < ara[j]){ //use getter than (>) symbol for sorting from getter than to less than
11                
12                temp = ara[i];
13                ara[i] = ara[j];
14                ara[j] = temp;
15                
16            }
17        }
18        
19    }
20    
21    for(i = 0; i < 10; i++){ //printing array sorted array elements
22        
23        printf("%d\t",ara[i]);
24    }
25    return 0;
26}
27
Kimberly
29 Sep 2019
1#include <stdio.h>
2
3struct student
4{
5    int rollno;
6    char name[80];
7    int marks;
8};
9
10void accept(struct student list[], int s);
11void display(struct student list[], int s);
12void bsortDesc(struct student list[], int s);
13
14int main()
15{
16    struct student data[20];
17    int n;
18
19    printf("Number of records you want to enter? : ");
20    scanf("%d", &n);
21
22    accept(data, n);
23    printf("\nBefore sorting");
24    display(data, n);
25    bsortDesc(data, n);
26    printf("\nAfter sorting");
27    display(data, n);
28
29    return 0;
30} 
31
32void accept(struct student list[80], int s)
33{
34    int i;
35    for (i = 0; i < s; i++)
36    {
37        printf("\n\nEnter data for Record #%d", i + 1);
38        
39        printf("\nEnter rollno : ");
40        scanf("%d", &list[i].rollno);
41
42        printf("Enter name : ");
43        gets(list[i].name);
44
45        printf("Enter marks : ");
46        scanf("%d", &list[i].marks);
47    } 
48}
49
50void display(struct student list[80], int s)
51{
52    int i;
53    
54    printf("\n\nRollno\tName\tMarks\n");
55    for (i = 0; i < s; i++)
56    {
57        printf("%d\t%s\t%d\n", list[i].rollno, list[i].name, list[i].marks);
58    } 
59}
60
61void bsortDesc(struct student list[80], int s)
62{
63    int i, j;
64    struct student temp;
65    
66    for (i = 0; i < s - 1; i++)
67    {
68        for (j = 0; j < (s - 1-i); j++)
69        {
70            if (list[j].marks < list[j + 1].marks)
71            {
72                temp = list[j];
73                list[j] = list[j + 1];
74                list[j + 1] = temp;
75            } 
76        }
77    }
78}
María Camila
13 Oct 2017
1 #include <stdio.h>
2    void main()
3    {
4 
5        int i, j, a, n, number[30];
6        printf("Enter the value of N \n");
7        scanf("%d", &n);
8 
9        printf("Enter the numbers \n");
10        for (i = 0; i < n; ++i)
11            scanf("%d", &number[i]);
12 
13        for (i = 0; i < n; ++i) 
14        {
15 
16            for (j = i + 1; j < n; ++j)
17            {
18 
19                if (number[i] > number[j]) 
20                {
21 
22                    a =  number[i];
23                    number[i] = number[j];
24                    number[j] = a;
25 
26                }
27 
28            }
29 
30        }
31 
32        printf("The numbers arranged in ascending order are given below \n");
33        for (i = 0; i < n; ++i)
34            printf("%d\n", number[i]);
35 }
queries leading to this page
best sort algorithm javasorting csorting algorithms in c with explanationsorrt array in csorting using function in calgorithm of sorting array in csorting algorithm javain built sorting function in csort size in csort in ascending order in cdifferent types of sorting algorithm in csorting accesnding in cvarious sorting algorithmssort arrray in csort array c functionselection sort implementation csort elements in array in ascending order in ctypes of sorting techniques in csort an array algorithm in chow to declare an sort 28 29 function in csorting explain in chow to sort in csorting elements in ascending orderc program sortgiven an array sort it using c languageinsertion sort in csort in c functionc sorting algorithmssyntax array sort in cascending order c program using arrayc sort numbers in array c language sorting code to sort an array in csort array in java algorithemhow to sort list in c languagesorting numbers in c programmingsorting algorithms explainedwhat is sorting algorithmshow to sort an array in csorting algorithms javawhat is sorting in chow to sort array in ascending order chow to sort struct elements in csorting a c arraycalling a function for sorting array it in cjava sorting algorithmarrays sort in carrange the array in ascending order in csorting array in c codesorting in array in call sorting algorithms code in csort algorithms object javasorting in an array in cinteger array sorting in chow to sort array elements in csort an array in ascending orderascending order in c programsorting an arrayc programming sort arraysorting algorithms in data structuresadvanced sorting algorithms javac program sort functionsort code chow to sort an array in ascending orderarray sort algorithm in javasort numbers in array csorting the elements in an array in chow to sort an arry in csorting an array in cc array sortc program sortingwrite a program to implement sorting an array in csorting any type in csorting methods in csort numbers c codesorting function call sorting algorithms implementation in javasorting algorithm stepshow to sort numbers in a array in ceasy way to sort an array in csort arrat csort element without using sorting algorithm in aray in csort the values in array cwhich is best sorting algorithm in javaarrange a structure in ascending order ceasiest sort algorithm javahow to sort a number array in c write a program to sort an arrayc program to sort numbers in ascending orderarray sorting functions in c programmingsort algoritimn javawrite a program to sort given array in ascending order sorted elements in cc sorted arraybest sort algorithm in chow to sort arrau in csort technique in javajava sorting algorithmsselection sort in c using functionaccending arraywhat sorting algorthim java usesc program accending ordersort 28 29 in carray accending order csorting program in c tlebest sorting algorithm cdifferent sorting algorithms in javahow to arrange numbers in ascending order in c using arraysort program in carrange array in ascending order in csort array in ascending ordersorts array cwhat is data structure sorting in chow to sort array elements in ascending order in csort array java algorithmssort arrayin csimple sorting in csort element of array in carray sorting libraris cc program to sort an arrayprogram to sort an array in ascending order in csort a array csorting out data using array in csort algorithms javasort items in array in chow is java sortingc sortingsort array in c using functionsort algorithm java implementationoperation used by selection sort in chow to sort values in an array in cc sorting algorithmsimple java sorting algorithmsort algorthm javasort function in cc sort array in ascending ordersorting algorithm in csort function ccode to sort array in ascending orderhow to get sorta algorithm in javahwo to sort an array in chow to sort structures in csort algorithm in javabuilt in array sort in chow to sort the values of a structure in cascending sort in csorting meaning and carray sorting in csorting any type of data in csort elements in array in ascending ordersort array in ascending order cwhat is sort function in cjava arrays sort what algorithemsorting algosarrange an array in ascending order csorting algorithms in c 2b 2bsort c codesorting elements inside an array in cjava sorting algorithms examplessimplest sorting algorithm in csorted array in ascending order csorting of array in c in ascending ordersorting in ascending order in cselection sort program in csorting algorithms c 2b 2bc how to sorthow to sort array in c using inbuiltwrite a c program to convert an array into ascending ordersorting the array elements in cc code sorting algorithmseasiest way to sort an array in cjava built in sort algorithemsorder array chow to osrt an array in carray sort csorting in c 2b 2b problem setsaray sorting in csorting in ds in csorting algorithms in chow to declare a sort 28 29 function in csorting algloritjhmsorting program in c mcqsorting a array in chow to sort data in csorting algorithem in javaprint array in ascending orderprogram to sort the arrayc sort structuresort the array in cc array sorting algorithmssorting in javaall sorting algorithms listc array sort algorithmssort algorithm cfunction array sort in calgorithm for selection sort in cwrite a c program to read n unsorted integers and sort them in ascending orderbest sorting method in carray sort in csort structure array in chow to make sorting program in cc programming sortingascending order c programsorting in c using functionsorting algorithm in javasort algorithms javasorting array in cc program to convert ascending order of arraysorting java algorithmssort b in cstructures c how to sortsortening array number in ascending order c programing sorted array in cbuild own sort function cdefine sorting in cprogram to sort array elements in an array csorting programs in csorting algorithms cwhich is best sorting algorithm in cwhich sorting algorithm is used in javasort in java built on which algorithmdata structure sorting in cc sort array functionsort elements in array in csorting numbers in csorting in c programmingsort array in ascending ordersorting techniques in csorting in ascending orderserial sorting algorythmsselection sort program in c using functionsorting the string appears in cwhat algorithm does java sort usesorting in data structuresorting algorithms listarray sorting cselection sort in c algorithmsorting array of structures in cc program to sort arraynumber ascending order in carray c sortingc program to sort an array in ascending ordersteps in sorting array using c codewrite a program to sort elements of an array in ascending orderc sorting programall sorting algorithms in cc sorting array of intsort array in ascending order in csorting an array in ascending ordersorting algorithms in data structurearray sort algorithmsorting algorithmsorting algorithms in javaselection sort in in cwhich sorting algorithm is implemented in sort function in javaasc sort in csort ascending in cwhat is the use of program to sorting algorithms javac selection sortall sorting algorithms in javacocktail sort c programarrange an array in ascending ordersorting through array in ca function 2c sort in c how to arrange an array in ascending ordersorting in call sorting algorithms javaa function to sort an array in csorting array program in csort in c programsorting an array using chow do i sort numbers in an array csorting an array of integers in ccode for sorting an array in ccode to sort a list in cselection sort c programsort algorithm in java codeprogram to sort an array in c programmingefficient sort in cjava sort method algorithmsorting algorithms site 3ageeksforgeeks orgjava sort algorithmfastest way to sort in cwhich sorting algorithm java usesstruct sorting in ascending order in cis there a sort function in csortning array number in asccending order c programingsort algorithmcalling a function and sorting it in cwrite a program to sort array in chow to sort array in ascending order in chow to arrange array in ascending order in csort func in cwhat sorting algorithm does java usesort in c arrayc sort the arrayhow to count sorting in csorting array csorting element in ascending order using function in csorting algorithm chow to pass function in sort in csorting of array in cshort array in assending orderc code for sortingsorting an array csorting program in carray number sorting csorting algorithms in data sciroccosort function in array in csort arrays in cc sort an arraythe 24sort in carray sort function in chow sort an array in csort array elements in ascending order in cprogram to sort arrayc program sort arrayselection sorting program in csort array in c functionwhich sort algorithm is used in javacan sorting algorithms work on all datastructures 3ffunction to sort an array in cbest sorting algorithm javasort variables in array in csort command in csorting algorithms java programizsort an array in c programc program to sort n numbers using arraysorting of arraysort array c algorithmsorting in inc order in chow to sort elements of an array in csort array function cnumber array sorting in csimple sorting algorithms ccolumn sorting in cjava built in sorting algorithmsorder array in csorting integers in array in carrange array elements in ascending orderhow to organize an array cbest way to sort array in cc sort array simplestnumber sorting program in calgorithm that java uses to sortsorting function in calgorithm sorting javaall sorting algorithmslearn sorting algorithms in cdifferent sorting techniques in cc program to sort an array in ascending order using functionselection sort algorithm in cthe best sorting algorithm javadifference in c 2b 2b sorting algorithmsc sort structure arrayascending order sorting in cfastest way to sort an array in cbuble sort cnumber sorting in csorting algorithmssorting a structure in csorting algorithms java tutorialsort a list of numbers in calgorith of sorting an arratlogic for soting an arraysort algorith javaprogram to sort an array in ascending ordersorting in c programc sorting arraysimple sort algorithm in csorting algo in javasort algorithm method javaarrange array in ascending orderhow to sort numbers in c programmingsort the array in ascending order in cwhat algorithm does java use for sortingwhich sorting algorithm is used by java sortarray sorting in c languagejava sort what algorithmhow to make a sorting algorithm javasort array ascending ordersort function program in csort c programsorting algorithms javapc sort functionhow to sort from a value in csort using csort an array of arrays cdifferent sorting methods in csort array cascending order program in csort an array algorithmsort function in c languagehow to sort array of structures in csorting in structure in cc program to sort array using sortsort function in c for arrayc sorting programsmerge sort in call sorting program in ctypes of sorting in csort ascending order in csort array in cis sort 28 29 available in cc how to make array in asecding ordersorting c programc sort algorithm what is data structure sorting in chow to sort a structure in chow to order an array in csorting in c with functionc sort algorithmssort algorithm in cusing sort function in cc array sort algorithmselection sort c codewrite a program to sort an arraysort an array c functionsort algorithms in javasorting an integer in cselection sort ccalling a function for sorting array in csimple sorting program in csort an array csorted program in chow to sort array in carrange numbers in ascending order in csorting an array in c libraryhow to sort carray sorting methodshow to arrange an array in ascending order csorting elements in an arrayhow to sort array in c languagesort elements in ascending order c programsorting struct in csorting methodsbest sorting algorithm in csorting e 3blementsx in ana arraywrite a program to sort an array 3f in csorting of the arraysorting algoeithms in carray sort java uses which sorting algorothmjava sorting method what algorithm is usedsort and array in cjava algorithms for sorting arrayc program to sort no in arraysorting algroths in javasort algorithm javac how to sort an arraysimple sortiong algorithm c 2b 2bprogram in c to sort an array usingis any built in function in c to sort an arrayc sort arraybest sorting algorithm in javabest sorting algorithms in javahow to sort javasorting enum javac code to sort an arraysort cselection sort in chow to sort the value in array cselection sorting in csort algoritm javasorts in data structureascending order in ccan i sort a structure in cc function sort arrayhow to sort an arrat in cinclude sort in c sort array chow to arrange array in ascending orderc programming slice of array ascendingsorting using chow to sorting in c programmingprogram to sort elements by numberascending order in array in csort a array in c with o 28n 29sort in cdorting of a array in csorting order in csorting algorythms javadoes c have any sorting functionascending function in csorting algorithm for array in csort 28 29 in codeprogram to sort an arrayarray sort in chow to sort an array csort array elements in ascending orderjava uses which sorting algorithmacescending order method cascending order array in csorting an array and print in clist sort javac language sort arrayexplain sorting in csort integer array csorting an array in ascending order in cfunction for sorting array in cc program to sort array in ascending orderarray sort method in carray sort easy way in csort a list in chow to sort structure elements in cc program to sort the array in an ascending orderc array sort functionsorting algorithms in java with examplessorting function in csorting number with cc program to find ascending ordersort array of structures in csort an array in c sort in csorting javahow to approach building a sorting algorithm in cc program ascending orderis sorted array in cbest sorting algorithms javac array sorting algorithmhow to sort and array in csort inbuilt in csorting types in csort the element of array in csorting in c