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


Please Help Members By Posting Answers For Below Questions

Is c++ the hardest programming language?

735


You have two pairs: new() and delete() and another pair : alloc() and free(). Explain differences between eg. New() and malloc()

691


what does the following statement mean? int (*a)[4]

700


When one must use recursion function? Mention what happens when recursion functions are declared inline?

731


What is the syntax for a for loop?

693






What is ofstream c++?

696


What is the difference between *p++ and (*p)++ ?

860


Is atoi safe?

701


How java is different from c and c++?

813


What is the use of bit fields in structure declaration?

627


What is name hiding in c++?

735


Explain about Virtual Function in C++?

691


Differentiate between the manipulator and setf( ) function?

701


When do we use copy constructors?

685


Evaluate the following expression as C++ would do :8 * 9 + 2 * 5 a) 82 b) 79 c) 370 d) list

705