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
Is c++ the hardest programming language?
You have two pairs: new() and delete() and another pair : alloc() and free(). Explain differences between eg. New() and malloc()
what does the following statement mean? int (*a)[4]
When one must use recursion function? Mention what happens when recursion functions are declared inline?
What is the syntax for a for loop?
What is ofstream c++?
What is the difference between *p++ and (*p)++ ?
Is atoi safe?
How java is different from c and c++?
What is the use of bit fields in structure declaration?
What is name hiding in c++?
Explain about Virtual Function in C++?
Differentiate between the manipulator and setf( ) function?
When do we use copy constructors?
Evaluate the following expression as C++ would do :8 * 9 + 2 * 5 a) 82 b) 79 c) 370 d) list