Skip to main content

Insertion sorting in c language

Insertion sorting in c language

Sorting is the process of arrenging data in ascending or decending order.
Like- dictionary
You think that if alphabets is not in sorted way how you can find any word.
To handle it we can sorted char,int.

THEORY-

in insertion sorting















each next element is compare all element behind it.

syntax-

#include<stdio.h>
int main()
{ int n,i,j,a[1000],temp;
printf("enter how many no you wanted to sort\n");
scanf("%d",&n);
printf("ENTER NO FOR SORTING\N");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
temp=a[i];
for(j=i-1;j>=0;j--)
if(a[j]>temp)
{
a[j+1]=a[j];
}
else
break;
a[j+1]=temp;
}
printf("SORTED \n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}



                                        exit

if you have any doubt please comment.and tell me what topic you want to learn.

Comments

Popular posts from this blog

top 10 youtuber of india

        TOP 10 YOUTUBER OF INDIA we are live in that age where everyone is know about youtube.Most of the people open youtube minimum twice in a day. Competition on youtube is so high that people are judge other people by know that which channel he visit. In india jio telecom increase the lavel of youtube. 1.AMIT BHADANA current subscribers-13M TYPE OF CHANNEL-comedy 13 millions is not a just a small number.Amit is very popular everywhere city or village. Amit has a big no of followers. the good things about there videos is that he never use a single words of abuse. we love him. 2.BB KI VINES-BHUVAN BAM current subscribers-12M TYPE OF CANNEL-comedy now come the best youtuber of student specially engineers. in his videos he play many role that is extra ordinary.his comedy is super he has a very good sense of humour.he is very stylish. 3.GOURAV- CHANNEL NAME- TECHNICAL GURUJI               ...

solution of PRIME1 - Prime Generator on spoj

PRIME1 - Prime Generator solution- #include<stdio.h> #include<math.h> int main() {int t; long long int l,h,i,flag; scanf("%d",&t); while(t--) { scanf("%lld%lld",&l,&h); while(l<=h) { flag=0; for(i=2;i<=sqrt(l);i++) { if(l%i==0) { flag=1;     break; } } if(flag==0) { if(l!=1) printf("%lld\n",l); } l++; } printf("\n"); } return 0; }