Page

Thursday, 30 August 2018

program for insertion a number in array

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,num,pos,a[10];
clrscr();
printf("enter no of element in array \n");
scanf("%d",&n);
for (i=0;i<n;i++)
{
printf("\n enter element ");
scanf("%d",&a[i]);
}
printf("\n enter no. to be inserted ");
scanf("%d",&num);
printf("\n enter position of array ");
scanf("%d",&pos);
for (i=n;i>=pos;i--)
{
a[i+1] = a[i];
}
a[pos] = num;
n++;
printf("\n after insertion");
for (i=0;i<n;i++)
{
printf("%d",a[i]);
}
getch();
}



No comments:

Post a Comment