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 use of bit field?
What is static volatile in c?
In a byte, what is the maximum decimal number that you can accommodate?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
how to execute a program using if else condition and the output should enter number and the number is odd only...
Explain how do you view the path?
Why does notstrcat(string, "!");Work?
In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.
What is difference between structure and union in c programming?
Disadvantages of C language.
Can include files be nested?
When do we get logical errors?
Explain how many levels deep can include files be nested?
#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }