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

What are the methods of exporting a function from a dll?

646


Is java as fast as c++?

595


How do you master coding?

558


What is static in c++?

592


List down the guideline that should be followed while using friend function.

644






In inline " expression passed as argument are evalauated once " while in macro "in some cases expression passed as argument are evaluated more than once " --> i am not getting it plz help to make me understand....

1945


What is function prototyping?

618


Can a list of string be stored within a two dimensional array?

571


Give example of a pure virtual function in c++?

583


Is it possible to pass an object of the same class in place of object reference to the copy constructor?

566


What is the fastest c++ compiler?

582


Is c++ the best programming language?

536


How would you implement a substr() function that extracts a sub string from a given string?

561


Write about the local class and mention its use?

605


List the types of polymorphism in c++?

622