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


Please Help Members By Posting Answers For Below Questions

Explain what are the sizes and ranges of the basic c++ data types?

638


What is nested class in c++?

514


What is purpose of abstract class?

582


What is lazy initialization in c++?

650


How will you call C functions from C ++ and vice-versa?

652






How do I start a c++ project?

583


What are libraries in c++?

601


C is to C++ as 1 is to a) What the heck b) 2 c) 10

635


What is class definition in c++ ?

625


Explain the virtual inheritance in c++.

590


What is polymorphism in c++? Explain with an example?

605


What is the best c++ compiler?

590


What are the data types in c++?

513


Mention the ways in which parameterized can be invoked.

532


How a modifier is similar to mutator?

626