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


Please Help Members By Posting Answers For Below Questions

Tell me when would you use a pointer to a function?

812


Write the syntax and purpose of a switch statement in C.

846


How can I run c program?

932


How are structure passing and returning implemented?

771


What is the difference between a free-standing and a hosted environment?

895


What are variables and it what way is it different from constants?

1003


Is there sort function in c?

785


what do you mean by enumeration constant?

786


Where does the name "C" come from, anyway?

866


i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none

825


Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor

3228


How do you convert strings to numbers in C?

925


write a program to generate address labels using structures?

4285


Is c still used?

796


Why do we use null pointer?

784