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

Why do we use templates?

593


How do I use turbo c++?

545


What are the characteristics of friend functions?

559


How much do c++ programmers make?

559


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

608






What is c++ hiding?

616


Write a program to encrypt the data in a way that inputs a four digit number and replace each digit by (the sum of that digit plus 7) modulus 10. Then sweep the first digit with the third, second digit with the fourth and print the encrypted number.

2088


How does c++ sort work?

553


Do you know what are pure virtual functions?

636


What is a class definition?

609


what is a reference variable in C++?

656


Explain the operation of overloading of an assignment operator.

687


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

566


What are the 2 main types of data structures?

580


What does obj stand for?

624