//CODE
#include<stdio.h>
int main()
{
int i,n,num,pos,a[10];
printf("\n Enter the size of the array:");
scanf("%d",&n);
printf("\n Enter the elements of the array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n Enter the number to be inserted:");
scanf("%d",&num);
printf("\n Enter the position at which the number has to be added:");
scanf("%d",&pos);
for(i=n;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=num;
printf("\n The array after insertion of %d is:",num);
for(i=0;i<n+1;i++)
{
printf("\n a[%d] = %d",i,a[i]);
}
return 0;
}
//OUTPUT
Enter the size of the array:5
Enter the elements:9
7
8
2
3
4
Enter the number to be inserted:10
Enter the position at which the number has to be added:3
The array after insertion of 10 is:
a[0]=9
a[1]=7
a[2]=8
a[3]=10
a[4]=2
a[5]=3
a[6]=4
#include<stdio.h>
int main()
{
int i,n,num,pos,a[10];
printf("\n Enter the size of the array:");
scanf("%d",&n);
printf("\n Enter the elements of the array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n Enter the number to be inserted:");
scanf("%d",&num);
printf("\n Enter the position at which the number has to be added:");
scanf("%d",&pos);
for(i=n;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=num;
printf("\n The array after insertion of %d is:",num);
for(i=0;i<n+1;i++)
{
printf("\n a[%d] = %d",i,a[i]);
}
return 0;
}
//OUTPUT
Enter the size of the array:5
Enter the elements:9
7
8
2
3
4
Enter the number to be inserted:10
Enter the position at which the number has to be added:3
The array after insertion of 10 is:
a[0]=9
a[1]=7
a[2]=8
a[3]=10
a[4]=2
a[5]=3
a[6]=4
No comments:
Post a Comment
Note: only a member of this blog may post a comment.