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
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
What is the method to save data in stack data structure type?
How do I create a directory? How do I remove a directory (and its contents)?
Why malloc is faster than calloc?
If I have a char * variable pointing to the name of a function ..
Which control loop is recommended if you have to execute set of statements for fixed number of times?
What is the best way of making my program efficient?
Explain what are the standard predefined macros?
What is use of #include in c?
What is a program flowchart and explain how does it help in writing a program?
When would you use a pointer to a function?
I came across some code that puts a (void) cast before each call to printf. Why?
What is the difference between the expression “++a” and “a++”?
Is swift based on c?
What does void main () mean?