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
Why do we use templates?
How do I use turbo c++?
What are the characteristics of friend functions?
How much do c++ programmers make?
Evaluate the following expression as C++ would do :8 * 9 + 2 * 5 a) 82 b) 79 c) 370 d) list
What is c++ hiding?
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.
How does c++ sort work?
Do you know what are pure virtual functions?
What is a class definition?
what is a reference variable in C++?
Explain the operation of overloading of an assignment operator.
Is it possible to pass an object of the same class in place of object reference to the copy constructor?
What are the 2 main types of data structures?
What does obj stand for?