==> Please In C Language <==
Insert a value in a sorted array:
Given an integer array a[9] = { 2, 3, 5, 7, 11, 13, 17, 19 }, read in an integer k from the screen and insert k into the array so the new array remains sorted. Note that array a has size 9, but there are only 8 initial values. This ensures that no value will be lost after the insertion.
For example, when k=12 , the new array will be {2, 3, 5, 7, 11, 12, 13, 17, 19 };
when k = -5, the new array will be { -5, 2, 3, 5, 7, 11, 13, 17, 19 };
when k= 100, the new array will be { 2, 3, 5, 7, 11, 13, 17, 19, 100 }.
Given below is the code for the question. Please do rate the answer
if it helped. Thank you.
#include <stdio.h>
void print(int a[], int n);
int main(){
int a[9] = { 2, 3, 5, 7, 11, 13, 17, 19 };
int n = 8;
int index, i;
int k;
printf("The array elements are: \n");
print(a, n);
printf("Enter a value to insert: ");
scanf("%d", &k);
//find the correct index at which to insert
for(index = 0; index < n; index++){
if(k < a[index])
break;
}
//shift all elements to right to make space for new
value
for(i = n-1; i >= index; i--){
a[i+1] = a[i];
}
//now store new value
a[index] = k;
n++; //increment no. of elements
printf("After inserting %d the array elements are:
\n", k);
print(a, n);
return 0;
}
void print(int a[], int n){
int i;
for(i = 0; i < n; i++){
printf("%d ", a[i]);
}
printf("\n");
}

==> Please In C Language <== Insert a value in a sorted array: Given an integer...
Special array removal: Given an integer array a[8]= {2,3,5,7,11,13,17,19}, read in an integer k from the screen. When k is a valid array index (i.e., between 0 and 7), move a[k] to the end of the array and push the array elements after a[k] one position up front. Print out the elements in the array after this removal. If k is not a valid array index, print out an error message. For example, when k=2, the array will be changed...
Using C++ Insert elements into a partially filled array. a) Create a partially filled array of CAPACITY 100. b) Initialize the array with values 10,20,30,40,50,60,70,80,90,100 c) Create a print function for the array. d) Create an insert function which inserts an integer into the array in sorted position. e) Insert the numbers 5, 150 and 55. f) Print the array before and after each insertion. Output Example 10 20 30 40 50 60 70 80 90 100 5 10 20...
IN JAVA please Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Your code will be tested for runtime. Code which does not output a result in logarithmic time (making roughly log(2) N comparisons) will fail the tests. A sample main function is provided so that you may test your code on sample inputs. For testing purposes, the...
You are given an array containing integers in the sorted order: [O] [1] [2] [3] [4] [5] [6] [7] 6 9 17 29 33 41 58 61 [8] [9] [10] [11] [12] [13] 67 87 93 112 118 145 We want to find 12 in the given array, using binary search algorithm. The first comparison will be made with ----- 6 58 61 None. 12 is not in the array.
Write a mips program that defines two integer array that are pre-sorted and the same size (e.g., [3, 7, 9, 11, 15, 21] and [1, 4, 6, 14, 18, 19]) and a function merge that takes the two arrays (and their size) as inputs and populates a single array of twice the size of either input array that contains the elements of both arrays in ascending order. In the example arrays given, then output would be [1, 3, 4, 6,...
You will be given an array of N elements sorted small to large. For the X and Y values that satisfy the X ≤ Y condition, draw the flow diagram of the algorithm that finds the start and end addresses of the region with the numbers greater than X and less than Y with the divide and manage approach and with O (logN) complexity. Also code the algorithm in c language. (not c++) Example: A[0…8] array 3, 5, 7, 9,...
Define a function named insert that takes an integer atom and a sorted list as parameters. The function should return a list with the integer in the correct position in the sorted list. For example: insert [3, (2 4 6 8)] = (2 3 4 6 8) insert 9, ()] = (9) insert[3, (2 3 4 5)] = (23 3 4 5) Note that in the case of that last example, it does not matter which 3 comes first in...
Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...
1. What is the minimum number of locations a binary search algorithm will have to examine when looking for a particular value in a sorted array of 200 elements? (2 points) 1 6 7 8 200 2. In general, which of the following sorting algorithms is the MOST efficient? (2 points) Bubble sort Insertion sort Heap sort Merge sort Selection sort 3. Which of the following are quadratic-sorting algorithms? (2 points) I. insertion sort II. selection sort III. merge sort...
Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine library procedures Objectives: 1. using register indirect addressing 2. passing parameters 3. generating “random” numbers 4. working with arrays Description: Write and test a MASM program to perform the following tasks: 1. Introduce the program. 2. Generate ARRAYSIZE random integers in the range [LO = 10 .. HI = 29], storing them in consecutive elements of an array. ARRAYSIZE should be set to 200....