Question

In: Computer Science

# please answer question asap please Write a program in C to insert new value in...

# please answer question asap please

Write a program in C to insert new value in the array (unsorted list).

Use pointer notation for the array elements

.Test Data:Input the size of array: 4 Input 4 elements in the array in ascending order:

element -0: 2

element -1: 9

element -2: 7

element -3: 12

Input the value to be inserted: 5

Input the Position, where the value to be inserted: 2

Expected Output:The current list of the array:2 9 7 12

After Insert the element the new list is:2 5 9 7 12

Solutions

Expert Solution

C code:

#include <stdio.h>

int main()
{
int n;
printf("Input size of array: ");
scanf("%d",&n);
  
int arr[n],ele,pos;
int *p=arr;
for(int i=0;i<n;i++)
{
printf("Enter element - %d: ",i);
scanf("%d",(p+i));
}
  
printf("Input the value to be inserted: ");
scanf("%d",&ele);
  
printf("Input the Position, where the value to be inserted: ");
scanf("%d",&pos);
  
  
printf("Expected Output:The current list of the array: ");
for(int j=0;j<n;j++)
{
printf("%d ",*(p+j));
}
  

//main code
for(int i=n-1;i>=0;i--)
{
*(p+i+1)=*(p+i);
  
if(i==pos-1)
{
*(p+i)=ele;
break;
}
}

  
printf("\nAfter Insert the element the new list is: ");
for(int j=0;j<=n;j++)
{
printf("%d ",*(p+j));
}
}


Output:


Related Solutions

This is C++, please insert screenshot of output please. Part1: Palindrome detector Write a program that...
This is C++, please insert screenshot of output please. Part1: Palindrome detector Write a program that will test if some string is a palindrome Ask the user to enter a string Pass the string to a Boolean function that uses recursion to determine if something is a palindrome or not. The function should return true if the string is a palindrome and false if the string is not a palindrome. Main displays the result ( if the string is a...
Please if you are able to answer the question below: Write C++ program using native C++...
Please if you are able to answer the question below: Write C++ program using native C++ (you can use STL)  that produces Huffman code for a string of text entered by the user.  Must accept all ASCII characters.  Pleas explain how you got frequencies of characters, how you sorted them, how you got codes.
. NEED ANSWER ASAP / ANSWER NEVER USED BEFORE, COMPLETELY NEW ANSWER PLEASE Write a Strategic...
. NEED ANSWER ASAP / ANSWER NEVER USED BEFORE, COMPLETELY NEW ANSWER PLEASE Write a Strategic Marketing Plan on the Nike brand ,Write in depth detail on the following: Marketing Plan, Draft Environmental Issues Action Programs Budget and Breakeven-Point (BEP) ANSWER THROUGHLY 1-2 pages *** IN PARAGRAPGH FORM PLEASE NOT BULLET POINTS COPY AND PASTE Answer in paragraphs, and no picture attachment please. NEEDS TO BE AN ORIGINAL SOURCE ANSWER NEVER USED BEFORE
. EED ANSWER ASAP / ANSWER NEVER USED BEFORE, COMPLETELY NEW ANSWER PLEASE Write a Strategic...
. EED ANSWER ASAP / ANSWER NEVER USED BEFORE, COMPLETELY NEW ANSWER PLEASE Write a Strategic Marketing Plan on the Nike brand ,Write in depth detail on the following: Executive Summary Controls Self-Reflection ANSWER THROUGHLY 1-2 pages *** IN PARAGRAPGH FORM PLEASE NOT BULLET POINTS COPY AND PASTE Answer in paragraphs, and no picture attachment please. NEEDS TO BE AN ORIGINAL SOURCE ANSWER NEVER USED BEFORE *************MUST BE AN ORIGINAL SOURCE**************************
Write equivalent LLVM IR for the following SimpleC program. I need the answer ASAP please if...
Write equivalent LLVM IR for the following SimpleC program. I need the answer ASAP please if possible int x; int y; read x; y = x + 1; print y;
write C program to implement the priority queue with the operation insert
write C program to implement the priority queue with the operation insert
use linux or c program. please provide the answer in details. Write a program that will...
use linux or c program. please provide the answer in details. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally...
. NEED NEW ANSWER ASAP / ANSWER NEVER USED BEFORE NEED NEW ANSWER ASAP / ANSWER...
. NEED NEW ANSWER ASAP / ANSWER NEVER USED BEFORE NEED NEW ANSWER ASAP / ANSWER NEVER USED BEFORE Explain horizontal and vertical analysis. Do some research .explain why these methods are used. What can we learn from horizontal and vertical analysis statements? How can results vary compared to other corporations and why can ratios better than using dollars? ANSWER THROUGHLY 1 page *** IN PARAGRAPGH FORM PLEASE NOT BULLET POINTS COPY AND PASTE Answer in paragraphs, and no picture...
I need this written in C # ASAP Write a C# console program that continually asks...
I need this written in C # ASAP Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
Please answer the last step for question 1. Answer it asap please. Thanks 1. Consider the...
Please answer the last step for question 1. Answer it asap please. Thanks 1. Consider the following data for three different samples from three different populations:Consider the following data for three different samples from three different populations: Sample 1 Sample 2 Sample 3 0 6 6 4 8 5 0 5 9 1 4 4 0 2 6 T = 5 T = 25 T = 30 G = 60 SS = 12 SS = 20 SS = 14 ∑X2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT