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}
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#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
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 }