C Program For Insertion Sort

/*Insertion Sort*/


#include<stdio.h>
#include<conio.h>
void main(void)
{
int i=0,j,k,val,a[10];
clrscr();
printf("Enter the value");
scanf("%d",&val);
 while(val!=-9999)
 {
 k=i-1;
  while((val<a[k])&&(k>=0))
  {
  a[k+1]=a[k];
  k--;
  }
 a[k+1]=val;
 printf("Array after the inserting the value is\n");
  for(j=0;j<=i;j++)
  {
  printf("a[%d]=%d\n",j,a[j]);
  }
 printf("Enter the value\n");
 scanf("%d",&val);
 i++;
 }
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment