sorting program in c

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

showing results for - "sorting program in c"
Anna
24 Nov 2019
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}
María
06 Jan 2017
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}
Arianna
17 Jan 2020
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
Emmanuelle
29 Jul 2020
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}
Jonathan
30 Nov 2020
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 }
Luca
14 Oct 2017
1void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*))
queries leading to this page
sort size in cc qsort methodsimple sorting algorithms carray sort csort array elements in ascending order in cc sort functionsort items in array in cc sorted arrayhow to sort an array in ascending ordersorting a c arraysort function program in call sorting program in csorting meaning and cc array sortinghow to sort arrau in csort array cc program accending ordersorting algorithms in c with explanationhow to use qsort in cc selection sortc sorting arrayc array sort function librarysorting elements in an arraysort array c functionselection sort in c algorithmsorting array in c codecode to sort a list in cc sort array simplestascending sort in chow to sort structures in csort code chow to sort array in ascending order in cc function to sort an arraysort array according in cwrite a program to sort an array 3f in cc program to sort array using sorteasiest way to sort an array in cis any built in function in c to sort an arrayhow to sort the value in array csorting an array csort command implementation in casc sort in cusing sort function in csorting in array in csorting algorithm in cascending order program in csort program in cprogram to sort an arrayalgorithm for selection sort in cwhat is sort function in cdifferent sorting techniques in chow to arrange an array in ascending order csort inbuilt in cc array sorting algorithmssort an array c functionnumber array sorting in csorting function csort integer array cselection sort program in cprogram to sort an array in ascending order in csort the element of array in csort array in c using functionsort array ascending ordersort function in c for arrayarrange numbers in ascending order in cinclude sort in cc program sort arrayhow to sort an array csorting an array and print in chow sort an array in csort an array of arrays chow to sort an arry in cc program to find ascending orderc program to convert ascending order of arrayarray c sortingsorting c programfunction for sorting array in csort in ascending order in csort arrray in cshell sort in cascending order c program using arraysorting of array in c in ascending ordersorting in ascending orderarray sorting cdoes c have any sorting functionhow to pass function in sort in caccending arrayall sorting algorithms code in chow to sort an array in cprint array in ascending orderarrange array in ascending ordersorted elements in csort array in cis sort 28 29 available in clearn sorting algorithms in cc array sorting algorithmc programming slice of array ascendingsorting using function in cnumber ascending order in csorting through array in carray number sorting csort arrayin cmerge sort in csort element without using sorting algorithm in aray in csort a list of numbers in cqsort function in c explainedarrays sort in csort by asc in csort algorithm in csorting in c programminghow to sort array in c using inbuiltsorting a structure in chow to sort array in ctype of sort in cwrite a program to sort given array in ascending order how to sort data in csort the values in array csort an array in c programascending function in cwhich is best sorting algorithm in cfunction to sort an array in csort the array in csorting number with cc program to sort an array in ascending orderselection sort program in c using functiondorting of a array in csort an array in ascending ordersorting in c with functionhow to sort array of structures in cc program to sort an array write a program to sort an arraysorting array program in csort the array in ascending order in csort elements in array in ascending orderdata structure sorting in cprogram to sort elements by numbersorting explain in cis there any sort function in csorted array in cfunction array sort in csort command in cc sort the arrayefficient sort in chow to sort array in ascending order cc array sort algorithmsoperation used by selection sort in csorting an array in ascending order in ca function 2c sort in c qsort in csorting an array in c libraryarrange a structure in ascending order caray sorting in carray sorting functions in c programmingc sorting algorithmqsort function in csorting an array in ascending ordercan i sort a structure in cprogram to sort arraysorting the elements in an array in csort and array in chow to sort numbers in c programmingarrange array elements in ascending ordersorting algorithms in cc sort structure arraysorting integers in array in cc how to make array in asecding ordersort array in ascending order in cselection sort c programsort un csort array c algorithmarray sort in csorting of array in ctechnique of sortting in ccode to sort array in ascending orderc program to sort no in arraysorting an array of integers in carray sort in cinbuilt sort in csorted program in cinbuilt sort method in csorting numbers in c programmingarray sorting in c languagec sort array in ascending orderprogram to sort an array in c programmingc program to sort numbers in ascending orderc program to sort the array in an ascending ordersorting in cc array sort functionprogram to sort an array in ascending ordersort an array cascending order in c programnumber sorting in ccolumn sorting in cc sort algorithmcalling a function and sorting it in csorting elements in ascending ordersorting order in csort arrays in ccalling a function for sorting array it in csorting in c using functionsyntax array sort in csort algorithm csorting in structure in csortening array number in ascending order c programing easy way to sort an array in csimple sorting in chow to sort a structure in csort in c functionhow to sort and array in csorting using cc program to sort arrayc sortingsorting program in c mcqsort in c arraydifferent sorting methods in chow to sort array in c languagec language sorting arrange array in ascending order in cstructures c how to sortc insewrtion sortsorting an array using cc sorting arrayssort numbers c codesort a list in cprogram to sort array elements in an array csort elements in ascending order c programc sorting programsort func in chow to organize an array cinsertion sort in cc program sort functionsort keyword in chow to sort structure elements in csorting in ascending order in cselection sort algorithm in csorting array of structures in cinbuilt sort function in csort function in c languagecalling a function for sorting array in csorting accesnding in csorting function in cc how to sort an arrayhow to sort array elements in chow to sort numbers in a array in cwhat does qsort do in chow to sort struct elements in corder array cc code to sort an arraysorted array in ascending order csort c programsort elements in array in carrange an array in ascending order csort ascending in csorting elements inside an array in csorting methods in cascending order sorting in cwrite a c program to convert an array into ascending ordersort a array carray sort easy way in ca function to sort an array in cin built sorting function in cc code for sortingcode to sort an array in cc sort array functionhow to sort list in c languageall sorting algorithms in csort function in c 3d 3dsorting the array elements in corder array in cinserion sort in cprogram in c to sort an array usingis there a sort function in cbuilt in array sort in c what is data structure sorting in chow to sort the values of a structure in csimplest sorting algorithm in chow to make sorting program in csorting an integer in csorting array cbest way to sort array in cwhat is sorting in csort numbers in array csorting out data using array in csort cqsort csort b in cselection sort c codec sorting algorithmswhat is data structure sorting in calgorithm of sorting array in csort structure array in cc array sort algorithmsort an arry in csort in c programsimple sorting program in carray accending order cc array sortsorting of the arraysorting algorithms cascending order in array in csort a array in c with o 28n 29sort variables in array in cdoes c have sort functionsorting any type in carray sorting libraris csorting an arrayhow to order an array in csort array in ascending order cselection sort in in cselection sort in csort array in ascending orderhow to osrt an array in cbest sorting algorithm carray sort function in cnumber sorting program in cc program to sort n numbers using arraywrite a program to sort elements of an array in ascending orderthe 24sort in csort array elements in ascending orderfastest way to sort an array in csorting struct in cc sort array functinoarray sorting in csorting a array in csorting cdefine sorting in cselection sort in c using functionselection sort cimnsertion sort in cselection sort implementation csorting array function in cis sorted array in carray sort method in cc language sort arraysorting algoeithms in csorting element in ascending order using function in csorting an array in chow to sort from a value in csort an array algorithm in csort in csort function in csorting techniques in chow to declare an sort 28 29 function in csort array in ascending orderc sorting programstypes of sorting in csort elements in array in ascending order in csort using cc function sort arraysort element of array in csorts array chow to sort values in an array in csorting function in cbest sort algorithm in chow to sort elements of an array in csorting e 3blementsx in ana arrayarrange the array in ascending order in cc qsortbuild own sort functioin chow to arrange array in ascending orderascending order in chow to sorting in c programmingarray program to sort in cwrite a c program to read n unsorted integers and sort them in ascending orderhow to arrange an array in ascending orderselection sorting in cbest sorting algorithm in cc sorting array of intwrite a program to implement sorting an array in csorrt array in csorting numbers in carrange an array in ascending orderbuild own sort function csorting the string appears in csorting in c programc programming sort arrayhwo to sort an array in csorting array in csort function csort function in array in cwrite a program to sort array in chow to arrange array in ascending order in cbest sorting method in chow to approach building a sorting algorithm in cinteger array sorting in cc language sort functionhow to arrange numbers in ascending order in c using arrayc sort numbers in array how to sort a number array in csort an array in ctypes of sorting techniques in csorting programs in csorting in an array in cascending array sort in csorting in ds in clogic for soting an arrayhow do i sort numbers in an array csorting algorithm cc programming sortingbuble sort cshort array in assending orderprogram to sort the arrayc sort structuresort arrat csort array of structures in cc program sorthow to count sorting in cc program sortingcode for sorting an array in csort 28 29 in cselection sorting program in cfastest way to sort in cacescending order method chow to declare a sort 28 29 function in cqsort function implementation in cc how to sorthow does qsort work in csorting of arraysimple sort algorithm in cwrite a program to sort an arrayascending order array in c sort in csort ascending order in cc sort arrayc program to sort an array in ascending order using functionc program to sort array in ascending ordersorting program in csorting in inc order in cexplain sorting in cc sort an arraydoes c has inbuilt sort functionhow to sort array elements in ascending order in csorting program in c tlesort array in c functionsortning array number in asccending order c programingstruct sorting in ascending order in ccocktail sort c programc code sorting algorithmssorting types in chow to sort csorting algorithm for array in csort c codec program ascending orderascending order c programhow to sort an arrat in csorting any type of data in chow to sort in c sort array csorting program in c