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
Tell me when would you use a pointer to a function?
Write the syntax and purpose of a switch statement in C.
How can I run c program?
How are structure passing and returning implemented?
What is the difference between a free-standing and a hosted environment?
What are variables and it what way is it different from constants?
Is there sort function in c?
what do you mean by enumeration constant?
Where does the name "C" come from, anyway?
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
Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor
How do you convert strings to numbers in C?
write a program to generate address labels using structures?
Is c still used?
Why do we use null pointer?