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
How do I create a directory? How do I remove a directory (and its contents)?
Why is c called a structured programming language?
Explain how do you determine a file’s attributes?
Explain data types & how many data types supported by c?
Explain the difference between malloc() and calloc() in c?
Can you please explain the difference between strcpy() and memcpy() function?
What is the need of structure in c?
What are the data types present in c?
How do shell structures work?
What is the difference between strcpy() and memcpy() function in c programming?
Why do we need volatile in c?
in linking some of os executables are linking name some of them
A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM
The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this
which is an algorithm for sorting in a growing Lexicographic order