write a program to insert an element at the specified
position in the given array in c language
Answer Posted / prashant tyagi
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,item,n,a[10],loc,flg;
clrscr();
printf("Enter the limit N : ");
scanf("%d",&n);
if(n<=10)
{
for(i=1;i<=n;i++)
{
printf("a[%d] = ",i);
scanf("%d",&a[i]);
}
printf("\nEnter the Location = ");
scanf("%d",&loc);
for(j=1;j<=n;j++)
{
if(loc==j)
{
flg=1;
printf("Insert = ");
scanf("%d",&item);
for(i=n;i>=loc;i--)
{
a[i+1]=a[i];
}
a[loc]=item;
}
}
if(flg==1)
{
n++;
}
else
{
printf("Location not Found");
}
printf("\nNew List\n");
for(i=1;i<=n;i++)
{
printf("\n%d",a[i]);
}
}
else
{
printf("Limit is not Valid ");
}
getch();
}
| Is This Answer Correct ? | 24 Yes | 5 No |
Post New Answer View All Answers
What is identifier in c?
difference between Low, Middle, High Level languages in c ?
Explain how can I avoid the abort, retry, fail messages?
What is the use of a conditional inclusion statement in C?
What language is windows 1.0 written?
What are the 4 types of programming language?
What is main () in c language?
Can you please explain the difference between syntax vs logical error?
Explain what are preprocessor directives?
What are data structures in c and how to use them?
What is the difference between void main and main in c?
Explain how do you use a pointer to a function?
What are the advantages of c language?
Explain zero based addressing.
What is .obj file in c?