Related questions
#include <stdio.h>
int counter=0;
int size;
void deleteNumber(int array[],int index);
void insertNumber(int array[],int index,int value);
void insertIntelligently(int array[],int number);
void insertByvalue(int array[]);
void deleteByrange(int array[]);
void search(int array[]);
void ascendingOrder(int array[]);
void descendingOrder(int array[]);
void replace(int array[]);
void printArray(int array[]);
int main() {
int array[size], choice, i;
printf("Enter size of the array");
scanf("%d", &size);
for (i = 0; i < size; i++) {
printf("Enter the value for Index %d: ", i);
scanf("%d", &array[i]);
printf("\n");
counter++;
printf("%d", counter);
}
printArray(array);
printf("\nCounter is: %d \n", counter);
printf("\n");
while (choice != 9) {
printf("\n\nPress '1' to Insert by Index and Value \nPress '2' to Delete \nPress '3' to Insert by Value\nPress '4' to Delete By Range\nPress '5' to replace a value\nPress '6' to search a number\nPress '7' to print in ascending order\nPress '8' to print in descending order\n");
scanf("%d", &choice);
if (choice == 1) {
int index, value, option;
printf("Do you want to insert the nnumber intelligently or on a specific position?/n Press 1 to insert intelligently!!/n Press 2 to insert at a specific position!!");
scanf("%d", &option);
if (option == 1) {
int number;
printf("Enter number to place it intelligently!! ");
scanf("%d", &number);
insertIntelligently(array, number);
printArray(array);
} else if (option == 2) {
printf("Enter index to insert number at: \n");
scanf("%d", &index);
if (index > counter) {
printf("Enter Valid Index!\n");
} else {
printf("Enter value to insert: \n");
scanf("%d", &value);
insertNumber(array, index, value);
printArray(array);
}
} else if (choice == 2) {
int index;
printf("Enter index to delete number: \n");
scanf("%d", &index);
if (index >= counter) {
printf("Deletion not possible!!!\n");
} else {
deleteNumber(array, index);
}
printArray(array);
} else if (choice == 3) {
insertByvalue(array);
} else if (choice == 4) {
deleteByrange(array);
} else if (choice == 5) {
replace(array);
} else if (choice == 6) {
search(array);
} else if (choice == 7) {
ascendingOrder(array);
} else if (choice == 8) {
descendingOrder(array);
}
}
}
return 0;
}
void insertIntelligently(int array[],int number){
int i,j;
for(i=0;i<counter;i++){
if ( number > array[i] && number< array[i+1] )
{
for( j=counter-1 ; j >=i ; j--)
{
array[j+1]=array[j];
printf("++++");
}
array[i+1]=number;
counter+=1;
break;
}else printf("elseee");
}
}
void insertByvalue(int array[]){
int v;
printf("Enter value to insert: \n");
scanf("%d", &v);
array[counter]=v;
counter++;
}
void printArray(int array[]){
int j;
printf("Resultant Array is: ");
for (j=0;j<counter; j++){
printf("%d ", array[j]);
}
}
void deleteByrange(int array[]){
int fromIndex,toIndex,i,j;
printf("Enter the starting index: \n");
scanf("%d", &fromIndex);
printf("Enter the ending index: \n");
scanf("%d", &toIndex);
if(fromIndex>=counter || fromIndex<0){
printf("Invalid Index!!");
deleteByrange(array);
}
if(toIndex>=counter || toIndex<0){
printf("Invalid Index!!");
deleteByrange(array);
}
for(i=toIndex ; i>=fromIndex ; i--){
array[i]=array[i+1];
counter--;
}
printArray(array);
}
void replace(int array[]){
int index,value;
printf("Enter the index: \n");
scanf("%d",&index);
if(index<0 || index>counter-1){
printf("Enter Valid Index\n");
replace(array);
}
printf("Enter the value: \n");
scanf("%d",&value);
array[index]=value;
printArray(array);
}
void search(int array[]){
int key;
int low = 0;
int high = counter - 1;
int mid = (low+high)/2;
printf("Enter the value you want to search");
scanf("%d",key);
while (low <= high) {
if(array[mid] < key) {
low = mid + 1;
}
else if (array[mid] == key) {
printf("%d found at location %d", key, mid+1);
break;
}
else{
high = mid - 1;
mid = (low + high)/2;
}
}
if(low > high){
printf("Not found! %d isn't present in the list", key);
}
}
void ascendingOrder(int array[]){
int i,j,temp;
for(i=0;i<counter;i++){
for(j=i+1;j<counter;j++){
if(array[i]>array[j]){
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
}
void descendingOrder(int array[]){
int i,j,temp;
for(i=0;i<counter;i++){
for(j=i+1;j<counter;j++){
if(array[i]<array[j]){
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
printArray(array);
}
Step by stepSolved in 2 steps with 1 images
- Q1 #include <stdio.h> int arrC[10] = {0}; int bSearch(int arr[], int l, int h, int key); int *joinArray(int arrA[], int arrB[]) { int j = 0; if ((arrB[0] + arrB[4]) % 5 == 0) { arrB[0] = 0; arrB[4] = 0; } for (int i = 0; i < 5; i++) { arrC[j++] = arrA[i]; if (arrB[i] == 0 || (bSearch(arrA, 0, 5, arrB[i]) != -1)) { continue; } else arrC[j++] = arrB[i]; } for (int i = 0; i < j; i++) { int temp; for (int k = i + 1; k < j; k++) { if (arrC[i] > arrC[k]) { temp = arrC[i]; arrC[i] = arrC[k]; arrC[k] = temp; } } } for (int i = 0; i < j; i++) { printf("%d ", arrC[i]); } return arrC; } int bSearch(int arr[], int l, int h, int key) { if (h >= l) { int mid = l + (h - l) / 2; if...arrow_forwardC PROGRAMMING LANGUAGEarrow_forwardDescribe partial initialization of arrays during declaration.arrow_forward
- Can you fix the code please on the first picture shows the error output. // Corrected code #define _CRT_SECURE_NO_WARNINGS #include "LibraryManagement.h" #include "Books.h" #include "DigitalMedia.h" #include "LibraryConfig.h" #include #include #include #include // Include the necessary header for boolean data type // Comparison function for qsort to sort Digital Media by ID int compareDigitalMedia(const void* a, const void* b) { return ((struct DigitalMedia*)a)->id - ((struct DigitalMedia*)b)->id; } // initializing library struct Library initializeLibrary() { struct Library lib; lib.bookCount = 0; lib.ebookCount = 0; lib.digitalMediaCount = 0; // Initialize book array for (int i = 0; i < MAX_BOOK_COUNT; i++) { lib.books[i].commonAttributes.id = -1; // Set an invalid ID to mark empty slot } // Initialize ebook array for (int i = 0; i < MAX_EBOOK_COUNT; i++) { lib.ebooks[i].commonAttributes.id = -1; }...arrow_forwardc++ language using addition, not get_sum function with this pseudocode: Function Main Declare Integer Array ages [ ] Declare integer total assign numbers = [ ] assign total = sum(ages) output "Sum: " & total end fucntion sum(Integer Array array) declare integer total declare integer index assign total = 0 for index = 0 to size(array) -1 assign total = total + array[ ] end return integer totalarrow_forward#include <stdio.h> int arrC[10] = {0}; int bSearch(int arr[], int l, int h, int key); int *joinArray(int arrA[], int arrB[]) { int j = 0; if ((arrB[0] + arrB[4]) % 5 == 0) { arrB[0] = 0; arrB[4] = 0; } for (int i = 0; i < 5; i++) { arrC[j++] = arrA[i]; if (arrB[i] == 0 || (bSearch(arrA, 0, 5, arrB[i]) != -1)) { continue; } else arrC[j++] = arrB[i]; } for (int i = 0; i < j; i++) { int temp; for (int k = i + 1; k < j; k++) { if (arrC[i] > arrC[k]) { temp = arrC[i]; arrC[i] = arrC[k]; arrC[k] = temp; } } } for (int i = 0; i < j; i++) { printf("%d ", arrC[i]); } return arrC; } int bSearch(int arr[], int l, int h, int key) { if (h >= l) { int mid = l + (h - l) / 2; if...arrow_forward
- vWhat happens when an object such as an array is no longer referenced by a variable?arrow_forward1)Examine the above code that creates the array: a)How is the base type of the array specified? b)How is the length of the array specified? c)How many Strings are actually stored in the array after the array has been created? d)How is the base type of the ArrayList specified? e)How is the capacity of the ArrayList specified? f)What is the capacity of the ArrayList? g)What is the size of the ArrayList?arrow_forwardEnhanced selection sort algorithm SelectionSortDemo.java package chapter7; /** This program demonstrates the selectionSort method in the ArrayTools class. */ public class SelectionSortDemo { public static void main(String[] arg) { int[] values = {5, 7, 2, 8, 9, 1}; // Display the unsorted array. System.out.println("The unsorted values are:"); for (int i = 0; i < values.length; i++) System.out.print(values[i] + " "); System.out.println(); // Sort the array. selectionSort(values); // Display the sorted array. System.out.println("The sorted values are:"); for (int i = 0; i < values.length; i++) System.out.print(values[i] + " "); System.out.println(); } /** The selectionSort method performs a selection sort on an int array. The array is sorted in ascending order. @param array The array to sort. */ public static void selectionSort(int[] array) { int startScan, index, minIndex, minValue; for (startScan = 0; startScan < (array.length-1); startScan++) { minIndex = startScan; minValue...arrow_forward
- void changeAll(int x[]) { x[0] = x[0] + 5; return; The first element in an array would be increased by 5 The array would be the same because it was passed by value x would be increased by 5 All the elements in the passed array would be incremented by 5arrow_forwardQUESTION 22 Multiple Choice: Which java statement correctly processes an array variable ? O while (x < arr.length){ int value = arr[x]; x++; } %3D for(int x = 0; x < arr.length; x++){ int value = arr[x]; } %3D process(arr); do { int value = arr[x]; x++; } %3D while (x < arr.length); QUESTION 23 True or False: An array is a basic data type. O True Falsearrow_forwardWrite a function to determine the resultant force vector R of the two forces F1 and F2 applied to the bracket, where 01 and 02. Write R in terms of unit vector along the x and y axis. R must be a vector, for example R = [Rx, Ry]. The coordinate system is shown in the figure below: F1 y 02 01 1 ►x F2arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education