Insertion Sort In C

#include<stdio.h>
int main(){
	
	int arr[100],i,n,k,max;
	printf("Enter the element = ");
	scanf("%d",&n);
	printf("The array is : \n");
	for(i=1;i<=n;i++){
	printf("data %d : ",i);
	scanf("%d",&arr[i]);
	}
	printf("Enter the location you want to insert =");
	scanf("%d",&k);
	printf("Enter the item you want to insert =");
	scanf("%d",&max);
	
	for(i=k;i>=n+1;i--){
		arr[i+1]=arr[i];
	}
	arr[k]=max;
	n=n+1;
	printf("After insertion the arry is = \n");
	for(i=1;i<=n;i++){
		printf("%d = %d \n",i,arr[i]);
	}
	
	
}

Hits: 9

S M Mohaimanul Islam

Mad man loving technology.

Leave a Reply

Your email address will not be published. Required fields are marked *