Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit acb8151

Browse files
Merge pull request #152 from 1995Pradeep/patch-1
Create gariya_program.c
2 parents 28cc8d6 + 9dd5cf8 commit acb8151

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

c/gariya_program.c

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<stdio.h>
2+
int main(){
3+
4+
/* Here i & j for loop counters, temp for swapping,
5+
* count for total number of elements, number[] to
6+
* store the input numbers in array. You can increase
7+
* or decrease the size of number array as per requirement
8+
*/
9+
int i, j, count, temp, number[25];
10+
11+
printf("How many numbers u are going to enter?: ");
12+
scanf("%d",&count);
13+
14+
printf("Enter %d elements: ", count);
15+
// This loop would store the input numbers in array
16+
for(i=0;i<count;i++)
17+
scanf("%d",&number[i]);
18+
19+
// Implementation of insertion sort algorithm
20+
for(i=1;i<count;i++){
21+
temp=number[i];
22+
j=i-1;
23+
while((temp<number[j])&&(j>=0)){
24+
number[j+1]=number[j];
25+
j=j-1;
26+
}
27+
number[j+1]=temp;
28+
}
29+
30+
printf("Order of Sorted elements: ");
31+
for(i=0;i<count;i++)
32+
printf(" %d",number[i]);
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)