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
What is rtti in c++?
What is the difference between set and map in c++?
What is the size of integer variable?
Distinguish between new and malloc and delete and free().
What is prototype for that c string function?
Can constructor be static in c++?
Is linux written in c or c++?
Can you write a function similar to printf()?
How to demonstrate the use of a variable?
Describe private, protected and public – the differences and give examples.
How can a struct in c++ differs from a struct in c?
What is the this pointer?
What is null c++?
When you overload member functions, in what ways must they differ?
Where can I run c++ program?