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 the use of this pointer?
Define a nested class.
What is a namespace in c++?
What is the type of 'this' pointer? When does it get created?
Ask to write virtual base class code?
What is the difference between multiple and multilevel inheritance in c++?
Write a c program for binary addition of two 8 bit numbers.
What number of digits that can be accuratly stored in a float (based on the IEEE Standard 754)? a) 6 b) 38 c) An unlimited number
What is vector pair in c++?
Do class declarations end with a semicolon? Do class method definitions?
How can I improve my c++ skills?
Describe private, protected and public – the differences and give examples.
What are 2 ways of exporting a function from a dll?
Difference between struct and class in terms of access modifier.
How to demonstrate the use of a variable?