write a program to insert an element into an array
Answer Posted / sonia
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int a[10]={10,20,30,40,50,60,70,80,90};
int num,i,pos;
printf("enter the no which you want to insert");
scanf("%d",&num);
printf("enter the position");
scanf("%d",&pos);
if(pos<0 || pos>9)
{
printf("invalid position");
getch();
exit(0);
}
for(i=9;i>pos;i--)
a[i]=a[i-1];
a[pos]=num;
for(i=0;i<=9;i++)
printf(" %d",a[i]);
getch();
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What do nonglobal variables default to a) auto b) register c) static
How to access a variable of the structure?
What is a .h file c++?
What is the difference between while and do while loop? Explain with examples.
What is vector pair in c++?
What is the need of a destructor?
Is c++ proprietary?
what is C++ objects?
Will c++ be replaced?
What is the most powerful coding language?
How come you find out if a linked-list is a cycle or not?
What is while loops?
What is the best c++ compiler?
What is the equivalent of Pascal's Real a) unsigned int b) float c) char
What are the methods of exporting a function from a dll?