1#include <stdio.h>
2#include <conio.h>
3void main ()
4{
5 int a[100];
6 int temp,n,i,j;
7 printf("How many numbers do you want to enter? : ");
8 scanf("%d",&n);
9 for (i=0;i<n;i++)
10 {
11 printf("Enter %d number: ",i+1);
12 scanf("%d",&a[i]);
13 }
14
15 printf("\n\n.....arranging in ascending order.....\n\n");
16
17 for (i = 0; i < n; ++i)
18 {
19
20 for (j = i + 1; j < n; ++j)
21 {
22 if (a[i] > a[j])
23
24 {
25 temp = a[i];
26 a[i] = a[j];
27 a[j] = temp;
28 }
29 }
30 }
31
32 for (i=0;i<n;i++)
33 {
34 printf("%d ",a[i]);
35 }
36}
37
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}
1/* C program to arrange numbers in descending order DescOrder.C */
2
3#include <stdio.h>
4
5void main ()
6{
7 //variable declaration
8 int number[30];
9 int i, j, a, n;
10
11 //asking user to enter size of array
12 printf("Enter the value of N\n");
13 scanf("%d", &n); //reading array size
14
15 //asking user to enter array elements
16 printf("Enter the numbers \n");
17 for (i = 0; i < n; ++i)
18 scanf("%d", &number[i]); //reading array elements
19
20 /* Logic for sorting and checking */
21
22 for (i = 0; i < n; ++i)
23 {
24 for (j = i + 1; j < n; ++j)
25 {
26 if (number[i] < number[j])
27 {
28 a = number[i];
29 number[i] = number[j];
30 number[j] = a;
31 }
32 }
33 }
34
35 printf("The numbers arranged in descending order are given below\n");
36 for (i = 0; i < n; ++i)
37 {
38 printf("%d\n", number[i]); //printing numbers in descending order
39 }
40}