{"id":10907,"date":"2022-12-05T09:47:18","date_gmt":"2022-12-05T09:47:18","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=10907"},"modified":"2023-05-10T06:36:24","modified_gmt":"2023-05-10T06:36:24","slug":"c-program-to-sort-an-array-in-ascending-order","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/","title":{"rendered":"Ascending Order Program in C"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg\" alt=\"\" \/><\/p>\n<p>Ascending order refers to the arrangement of a set of numbers in increasing order, from the smallest value to the largest value. A program to sort numbers in ascending order in C can be useful for a variety of applications.<\/p>\n<p>The process of sorting a set of numbers in ascending order can be done using different sorting algorithms such as bubble sort, insertion sort, selection sort, and more. In general, the sorting algorithm works by comparing pairs of adjacent elements and swapping them if they are in the wrong order.<\/p>\n<p><strong>Original array<\/strong><\/p>\n<pre><code>5 2 8 7 1<\/code><\/pre>\n<p><strong>Array after sorting<\/strong><\/p>\n<pre><code>1 2 5 7 8<\/code><\/pre>\n<p>The order of the elements will be such that the smallest element, in this example 1, which is the smallest, will appear on the far left. On the far right, the greatest piece, in this case, 8 will be visible.<\/p>\n<h2>Logic Used to Sort an Array<\/h2>\n<p>The items may be sorted using a variety of reasoning. For the sake of simplicity, we will use a standard method used in ordinary living. In order to sort an <a href=\"http:\/\/prepbytes.com\/blog\/data-structure\/what-is-an-array-in-data-structure\/\" title=\"array\">array<\/a>, we choose a certain element and position it correctly by comparing it to other components.<\/p>\n<h3>Explanation<\/h3>\n<p>Take input array \u2018a\u2019 and no of elements(n) as 4<\/p>\n<p><strong>Let us take elements for array a={7,8,12,3}.<\/strong><\/p>\n<pre><code>1st iteration for(i=0;i&lt;n;i++) i.e. for(i=0;0&lt;4;i++)   \u2013 Outer for loop\n1st iteration for(j=i+1;j&lt;n;j++)  i.e. for(j=1;1a[j])  i.e. if(a[0]&gt;a[1]) i.e. if(7&gt;8)  false\n2nd iteration for(j=i+1;j&lt;n;j++)  i.e. for(j=2;2a[j])  i.e. if(a[0]&gt;a[1]) i.e. if(7&gt;12)  false\n\n3rd iteration for(j=i+1;j&lt;n;j++)  i.e. for(j=3;3a[j])  i.e. if(a[0]&gt;a[1]) i.e. if(7&gt;3)  true\ntemp=a[i];  i.e. temp=a[0]  i.e. temp=7\na[i]=a[j];  i.e. a[0]=a[3] i.e. a[0]=3\na[j]=temp; i.e. a[3]=7<\/code><\/pre>\n<p><strong>So now are array is a={3,8,12,7}<\/strong><\/p>\n<pre><code>2nd iteration for(i=1;i&lt;n;i++) i.e. for(i=1;1&lt;4;i++)   \u2013 Outer for loop\n1st iteration for(j=i+1;j&lt;n;j++)  i.e. for(j=2;2a[j])  i.e. if(a[1]&gt;a[2]) i.e. if(8&gt;12)  false\n\n2nd iteration for(j=i+1;j&lt;n;j++)  i.e. for(j=2;2a[j])  i.e. if(a[1]&gt;a[3]) i.e. if(8&gt;7) true\ntemp=a[i];  i.e. temp=a[1]  i.e. temp=8\na[i]=a[j];  i.e. a[1]=a[3] i.e. a[1]=7\na[j]=temp; i.e. a[3]=8<\/code><\/pre>\n<p><strong>So now are array is a={3,7,12,8}<\/strong><\/p>\n<pre><code>3rd iteration for(i=2;i&lt;n;i++) i.e. for(i=2;2&lt;4;i++)   \u2013 Outer for loop\n1st iteration for(j=i+1;j&lt;n;j++)  i.e. for(j=3;3a[j])  i.e. if(a[2]&gt;a[3]) i.e. if(12&gt;8)  true\ntemp=a[i];  i.e. temp=a[2]  i.e. temp=12\na[i]=a[j];  i.e. a[2]=a[3] i.e. a[2]=8\na[j]=temp; i.e. a[3]=12<\/code><\/pre>\n<p><strong>So now are array is a={3,7,8,12}<\/strong><br \/>\n<strong>Hence we have sorted the elements in ascending order a={3,7,8,12}.<\/strong><\/p>\n<h2>Algorithm for Sort an Array Elements<\/h2>\n<ul>\n<li>START<\/li>\n<li>INITIALIZE arr[] ={5, 2, 8, 7, 1 }.<\/li>\n<li>SET temp =0<\/li>\n<li>length= sizeof(arr)\/sizeof(arr[0])<\/li>\n<li>PRINT &quot;Elements of Original Array&quot;<\/li>\n<li>SET i=0. REPEAT STEP 7 and STEP 8 UNTIL i&lt;length<\/li>\n<li>PRINT arr[i]<\/li>\n<li>i=i+1.<\/li>\n<li>SET i=0. REPEAT STEP 10 to STEP UNTIL i&lt;n<\/li>\n<li>SET j=i+1. REPEAT STEP 11 UNTIL jarr[j]) then<br \/>\ntemp = arr[i]<br \/>\narr[i]=arr[j]<br \/>\narr[j]=temp<\/li>\n<li>j=j+1.<\/li>\n<li>i=i+1.<\/li>\n<li>PRINT new line<\/li>\n<li>PRINT &quot;Elements of the array sorted in ascending order&quot;<\/li>\n<li>SET i=0. REPEAT the below steps UNTIL i &lt; length<\/li>\n<li>PRINT arr[i]<\/li>\n<li>i=i+1.<\/li>\n<li>RETURN 0.<\/li>\n<li>END.<\/li>\n<\/ul>\n<h2>C Program for Array Sorting<\/h2>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_10897 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_10897 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_10897 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_10897 .wpsm_nav-tabs > li.active > a, #tab_container_10897 .wpsm_nav-tabs > li.active > a:hover, #tab_container_10897 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_10897 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_10897 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_10897 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_10897 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_10897 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_10897 .wpsm_nav-tabs > li > a:hover , #tab_container_10897 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_10897 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_10897 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_10897 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_10897 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_10897 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_10897 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_10897 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_10897 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_10897 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_10897 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_10897 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_10897\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_10897\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_10897_1\" aria-controls=\"tabs_desc_10897_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_10897\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_10897_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include &lt;stdio.h&gt;    \r\n     \r\nint main()    \r\n{      \r\n    int arr[] = {50, 20, 80, 70, 10};     \r\n    int temp = 0;    \r\n           \r\n    int length = sizeof(arr)\/sizeof(arr[0]);    \r\n         \r\n    printf(&quot;Elements of original array: &#92;n&quot;);    \r\n    for (int i = 0; i &lt; length; i++) {     \r\n        printf(&quot;%d &quot;, arr[i]);     \r\n    }      \r\n         \r\n    for (int i = 0; i &lt; length; i++) {     \r\n        for (int j = i+1; j &lt; length; j++) {     \r\n           if(arr[i] &gt; arr[j]) {    \r\n               temp = arr[i];    \r\n               arr[i] = arr[j];    \r\n               arr[j] = temp;    \r\n           }     \r\n        }     \r\n    }    \r\n        \r\n    printf(&quot;&#92;n&quot;);    \r\n            \r\n    printf(&quot;Elements of array sorted in ascending order: &#92;n&quot;);    \r\n    for (int i = 0; i &lt; length; i++) {     \r\n        printf(&quot;%d &quot;, arr[i]);    \r\n    }    \r\n    return 0;    \r\n}     \r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_10897 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_10897 a\"),jQuery(\"#tab-content_10897\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Time Complexity of Ascending order in C:<\/strong> O(N2)<br \/>\n<strong>Auxiliary Space of Ascending order in C:<\/strong> O(1)<\/p>\n<h2>Tips for Ascending Order Program in C<\/h2>\n<p>A <a href=\"http:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-sort-an-array-in-ascending-order\/\" title=\"sorting\">sorting<\/a> algorithm is used to reorder an array or list of elements in accordance with an element comparison operator. The new order of the items in the relevant data structure is determined using the comparison operator. Therefore, This article is the basic of the sorting algorithm and if you got these basic sorting methods you will be able to solve more difficult problems of sorting algorithms as in data structures and algorithms sorting bits of help in every advanced topic.<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nIn conclusion, sorting a set of numbers in ascending order is a fundamental operation in computer programming, and there are many different algorithms that can be used to accomplish this task. Whether you choose to use bubble sort, insertion sort, selection sort, or another sorting algorithm, the basic steps for writing a program to sort numbers in ascending order in C will remain the same.<\/p>\n<h2>Frequently Asked Questions<\/h2>\n<p><strong>Q1. What is the purpose of sorting numbers in ascending order?<\/strong><br \/>\n<strong>Ans.<\/strong> Sorting numbers in ascending order is a common task in programming and data analysis. It is useful when you want to organize data, identify patterns, or make calculations based on the order of the numbers.<\/p>\n<p><strong>Q2. Which sorting algorithm is the best for sorting numbers in ascending order?<\/strong><br \/>\n<strong>Ans.<\/strong> There is no one-size-fits-all answer to this question, as the best algorithm will depend on the size of the data set, the distribution of the data, and other factors. Some commonly used sorting algorithms for ascending order include bubble sort, insertion sort, selection sort, and quicksort.<\/p>\n<p><strong>Q3. How do I declare an array in C for sorting numbers in ascending order?<\/strong><br \/>\n<strong>Ans.<\/strong> You can declare an array of integers in C using the following syntax: int array_name[size_of_array]; where size_of_array is the number of elements in the array.<\/p>\n<p><strong>Q4. What is the time complexity of sorting algorithms for ascending order?<\/strong><br \/>\n<strong>Ans.<\/strong>The time complexity of sorting algorithms for ascending order can vary depending on the algorithm used. For example, bubble sort has a worst-case time complexity of O(n^2), while quicksort has an average-case time complexity of O(n log n).<\/p>\n<p><strong>Q5. What is the difference between ascending order and descending order?<\/strong><br \/>\n<strong>Ans.<\/strong> Ascending order refers to the arrangement of a set of numbers from smallest to largest, while descending order refers to the arrangement of a set of numbers from largest to smallest.<\/p>\n<p><strong><a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/basic-c-programs-examples\/\"><br \/>\nOther C Programs<\/a><\/strong><\/p>\n<p><a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/binary-search-program-in-c\/\" title=\"C Program for Binary Search\">C Program for Binary Search<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-add-two-numbers\/\" title=\"C Program to Add Two Numbers\">C Program to Add Two Numbers<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-calculate-percentage-of-5-subjects\/\" title=\"C Program to Calculate Percentage of 5 Subjects\">C Program to Calculate Percentage of 5 Subjects<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-convert-binary-number-to-decimal-number\/\" title=\"C Program to Convert Binary Number to Decimal Number\">C Program to Convert Binary Number to Decimal Number<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-convert-celsius-to-fahrenheit\/\" title=\"C Program to Convert Celsius to Fahrenheit\">C Program to Convert Celsius to Fahrenheit<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-convert-infix-to-postfix\/\" title=\"C Program to Convert Infix to Postfix\">C Program to Convert Infix to Postfix<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-find-area-of-circle\/\" title=\"C Program to Find Area of Circle\">C Program to Find Area of Circle<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-find-roots-of-quadratic-equation\/\" title=\"C Program to Find Roots of Quadratic Equation\">C Program to Find Roots of Quadratic Equation<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-reverse-a-linked-list\/\" title=\"C program to Reverse a Linked List\">C program to Reverse a Linked List<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-reverse-a-number\/\" title=\"C program to reverse a number\">C program to reverse a number<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/menu-driven-program-for-all-operations-on-doubly-linked-list-in-c\/\" title=\"Menu Driven Program For All Operations On Doubly Linked List in C\">Menu Driven Program For All Operations On Doubly Linked List in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/what-is-the-program-of-armstrong-number-in-c\/\" title=\"C Program for Armstrong Number\">C Program for Armstrong Number<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/c-program-for-merge-sort-for-linked-lists\/\" title=\"C Program For Merge Sort For Linked Lists\">C Program For Merge Sort For Linked Lists<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/c-program-for-performing-bubble-sort-on-linked-list\/\" title=\"C program for performing Bubble sort on Linked List\">C program for performing Bubble sort on Linked List<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/hello-world-program-in-c\/\" title=\"Hello World Program in C\">Hello World Program in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/perfect-number-program-in-c\/\" title=\"Perfect Number Program in C\">Perfect Number Program in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/leap-year-program-in-c\/\" title=\"Leap Year Program in C\">Leap Year Program in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/odd-even-program-in-c\/\" title=\"Odd Even Program in C\">Odd Even Program in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/selection-sort-program-in-c\/\" title=\"Selection Sort Program in C\">Selection Sort Program in C<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ascending order refers to the arrangement of a set of numbers in increasing order, from the smallest value to the largest value. A program to sort numbers in ascending order in C can be useful for a variety of applications. The process of sorting a set of numbers in ascending order can be done using [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-10907","post","type-post","status-publish","format-standard","hentry","category-c-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C Program to Sort an Array in Ascending Order<\/title>\n<meta name=\"description\" content=\"A sorting algorithm is used to reorder an array or list of elements in accordance with an element comparison operator.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C Program to Sort an Array in Ascending Order\" \/>\n<meta property=\"og:description\" content=\"A sorting algorithm is used to reorder an array or list of elements in accordance with an element comparison operator.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-05T09:47:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-10T06:36:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Ascending Order Program in C\",\"datePublished\":\"2022-12-05T09:47:18+00:00\",\"dateModified\":\"2023-05-10T06:36:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/\"},\"wordCount\":901,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg\",\"articleSection\":[\"C Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/\",\"name\":\"C Program to Sort an Array in Ascending Order\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg\",\"datePublished\":\"2022-12-05T09:47:18+00:00\",\"dateModified\":\"2023-05-10T06:36:24+00:00\",\"description\":\"A sorting algorithm is used to reorder an array or list of elements in accordance with an element comparison operator.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C Programming\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/c-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Ascending Order Program in C\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C Program to Sort an Array in Ascending Order","description":"A sorting algorithm is used to reorder an array or list of elements in accordance with an element comparison operator.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/","og_locale":"en_US","og_type":"article","og_title":"C Program to Sort an Array in Ascending Order","og_description":"A sorting algorithm is used to reorder an array or list of elements in accordance with an element comparison operator.","og_url":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-12-05T09:47:18+00:00","article_modified_time":"2023-05-10T06:36:24+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Ascending Order Program in C","datePublished":"2022-12-05T09:47:18+00:00","dateModified":"2023-05-10T06:36:24+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/"},"wordCount":901,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg","articleSection":["C Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/","url":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/","name":"C Program to Sort an Array in Ascending Order","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg","datePublished":"2022-12-05T09:47:18+00:00","dateModified":"2023-05-10T06:36:24+00:00","description":"A sorting algorithm is used to reorder an array or list of elements in accordance with an element comparison operator.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670230587606-Ascending%20order%20program%20in%20c.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/c-program-to-sort-an-array-in-ascending-order\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"C Programming","item":"https:\/\/prepbytes.com\/blog\/category\/c-programming\/"},{"@type":"ListItem","position":3,"name":"Ascending Order Program in C"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/10907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=10907"}],"version-history":[{"count":7,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/10907\/revisions"}],"predecessor-version":[{"id":16225,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/10907\/revisions\/16225"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=10907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=10907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=10907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}