Question: // CORRECT THE ERRORS AND MAKE SURE IT RUNS PERFECTLY ON DEV C ++.PLEASE SHOW ME THE OUTPUT SCREENSHOT// //IT IS A C PROGRAM//// DO

// CORRECT THE ERRORS AND MAKE SURE IT RUNS PERFECTLY ON DEV C ++.PLEASE SHOW ME THE OUTPUT SCREENSHOT//

//IT IS A C PROGRAM//// DO NOT CHANGE THE CODE. JUST CORRECT THE ERRORS AND MAKE SURE IT RUNS ON DEV C++//

//C Code:

//including all the required header files #include #include //function which generate the random numbers and return those numbers int* generateNumbers(){ //creating block to store 300 numbers int *ptr=(int*)malloc(sizeof(int)*300); //setting seed srand(191022310); //loop to generate numbers for(int i=0;i<300;i++) *(ptr+i)=rand(); return ptr; } //function for linear search int linearSearch(int *arr,int n,int element){ //loop that iterates over each element of an array for(int i=0;i

} //function for interpolation search int interpolationSearch(int *arr, int n, int x){ // Find indexes of two corners int lo = 0, hi = (n - 1);

// Since array is sorted, an element present // in array must be in range defined by corner while (lo <= hi && x >= arr[lo] && x <= arr[hi]) { if (lo == hi) { if (arr[lo] == x) return lo; return -1; } // Probing the position with keeping // uniform distribution in mind. int pos = lo + (((double)(hi - lo) / (arr[hi] - arr[lo])) * (x - arr[lo]));

// Condition of target found if (arr[pos] == x) return pos;

// If x is larger, x is in upper part if (arr[pos] < x) lo = pos + 1;

// If x is smaller, x is in the lower part else hi = pos - 1; } return -1; } // A recursive binary search function. It returns // location of x in given array arr[l..r] is present, // otherwise -1 int binarySearch(int *arr, int l, int r, int x){ if (r >= l) { int mid = l + (r - l) / 2;

// If the element is present at the middle // itself if (arr[mid] == x) return mid;

// If element is smaller than mid, then // it can only be present in left subarray if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);

// Else the element can only be present // in right subarray return binarySearch(arr, mid + 1, r, x); }

// We reach here when element is not // present in array return -1; } //Bubble sort to sort an array for binary and interpolation search void sort(int *ptr,int n){ for(int i=0;iptr[j]){ int temp=ptr[i]; ptr[i]=ptr[j]; ptr[j]=temp; } } } } int main(){ //Block for storing 300 numbers int *ptr=(int*)malloc(sizeof(int)*300); //store numbers in block ptr=generateNumbers();

//printing the numbers for(int i=0;i<300;i++) printf("%d ",*(ptr+i)); return 0; }

task 2:-

//including all the required header files #include #include #include //function which generate the random numbers and return those numbers int* generateNumbers(){ //creating block to store 300 numbers int *ptr=(int*)malloc(sizeof(int)*300); //setting seed srand(191022310); //loop to generate numbers for(int i=0;i<300;i++) *(ptr+i)=rand(); return ptr; } //function for linear search int linearSearch(int *arr,int n,int element){ //loop that iterates over each element of an array for(int i=0;i

} //function for interpolation search int interpolationSearch(int *arr, int n, int x){ // Find indexes of two corners int lo = 0, hi = (n - 1);

// Since array is sorted, an element present // in array must be in range defined by corner while (lo <= hi && x >= arr[lo] && x <= arr[hi]) { if (lo == hi) { if (arr[lo] == x) return lo; return -1; } // Probing the position with keeping // uniform distribution in mind. int pos = lo + (((double)(hi - lo) / (arr[hi] - arr[lo])) * (x - arr[lo]));

// Condition of target found if (arr[pos] == x) return pos;

// If x is larger, x is in upper part if (arr[pos] < x) lo = pos + 1;

// If x is smaller, x is in the lower part else hi = pos - 1; } return -1; } // A recursive binary search function. It returns // location of x in given array arr[l..r] is present, // otherwise -1 int binarySearch(int *arr, int l, int r, int x){ if (r >= l) { int mid = l + (r - l) / 2;

// If the element is present at the middle // itself if (arr[mid] == x) return mid;

// If element is smaller than mid, then // it can only be present in left subarray if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);

// Else the element can only be present // in right subarray return binarySearch(arr, mid + 1, r, x); }

// We reach here when element is not // present in array return -1; } //Bubble sort to sort an array for binary and interpolation search void sort(int *ptr,int n){ for(int i=0;iptr[j]){ int temp=ptr[i]; ptr[i]=ptr[j]; ptr[j]=temp; } } } } int main(){ //Block for storing 300 numbers int *ptr=(int*)malloc(sizeof(int)*300); //store numbers in block ptr=generateNumbers(); FILE *fptr; fptr = fopen("100data.txt", "w"); //handling errror condition if (fptr == NULL) { printf("Error!"); exit(1); } //writing data to file for(int i=0;i<300;i++){ fprintf(fptr, "%d ", *(ptr+i)); } fclose(fptr); //getting the last element //and adding all data into array //array to store numbers int a[300],x; fptr = fopen("100data.txt", "r"); for(int i=0;i<300;i++){ fscanf(fptr,"%d", &x); a[i]=x; } //printing last element printf("%d",x); fclose(fptr); return 0; }

// CORRECT THE ERRORS AND MAKE SURE IT RUNS PERFECTLY ON DEV C ++//

//IT IS A C PROGRAM////DO NOT CHANGE THE CODE .JUST CORRECT THE CODE .PLEASE SHOW THE OUTPUT SCREENSHOT//

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!