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
Explain what are the sizes and ranges of the basic c++ data types?
What is nested class in c++?
What is purpose of abstract class?
What is lazy initialization in c++?
How will you call C functions from C ++ and vice-versa?
How do I start a c++ project?
What are libraries in c++?
C is to C++ as 1 is to a) What the heck b) 2 c) 10
What is class definition in c++ ?
Explain the virtual inheritance in c++.
What is polymorphism in c++? Explain with an example?
What is the best c++ compiler?
What are the data types in c++?
Mention the ways in which parameterized can be invoked.
How a modifier is similar to mutator?