Posted by: Sourav | May 14, 2015

Insert an element in a already sorted array


#include<stdio.h>

void main()
{
int  m,n,o,p;int arr[100];
printf(“Enter the size\n”);
scanf(“%d”,&m);
for(o=0;o<m;o++)
arr[o]=o;
for(o=0;o<m;o++)

printf(“%d\n”,arr[o]);
printf(“Enter the position to insert \n”);
scanf(“%d”,&n);
printf(“The position entered is %d\n”,n);
while(m>n)
{
arr[m]=arr[m-1];
printf(“The %d position of arr has %d\n”,m,arr[m]);
m–;
}
for(o=0;o<4;o++)
printf(“%d\n”,arr[o]);
printf(“enter the element”);
scanf(“%d”,&arr[n]);
for(o=0;o<4;o++)
printf(“%d\n”,arr[o]);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: