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

Is map ordered c++?

592


When must you use a pointer rather than a reference?

598


What is the iunknown interface?

674


What is function overriding in c++?

603


Are strings mutable in c++?

692






What are keywords in c++?

598


What is the best c++ book for beginners?

568


What is flush c++?

538


Explain about Garbage Collector?

644


Is c++ proprietary?

575


What is c++ course?

576


What is a memory leak c++?

588


What is an iterator class in c++?

594


Is it possible to provide special behavior for one instance of a template but not for other instances?

626


What is the difference between a baller and a reference in C++?

574