write a program to insert an element into an array
Answer Posted / debasmit
#include <stdio.h>
int main()
{
int array[100], position, c, n, value;
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d elements\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter the location where you wish to insert an
element\n");
scanf("%d", &position);
printf("Enter the value to insert\n");
scanf("%d", &value);
for (c = n - 1; c >= position - 1; c--)
array[c+1] = array[c];
array[position-1] = value;
printf("Resultant array is\n");
for (c = 0; c <= n; c++)
printf("%d\n", array[c]);
return 0;
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Is dev c++ a good compiler?
What can c++ be used for?
When are exception objects created?
How the delete operator differs from the delete[]operator?
Can circle be called an ellipse?
Which bit wise operator is suitable for checking whether a particular bit is on or off?
What is Destructor in C++?
How do you invoke a base member function from a derived class in which you have not overridden that function?
What is public, protected, private in c++?
Which is the best c++ compiler for beginners?
What are abstract data types in c++?
What is private, public and protected inheritance?
Write a Program to find the largest of 4 no using macros.
How will you call C functions from C ++ and vice-versa?
If a header file is included twice by mistake in the program, will it give any error?