Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in which you create a 2D array of type double with 40 rows and 1

ID: 3685915 • Letter: W

Question

Write a program in which you create a 2D array of type double with 40 rows and 10 columns. Populate it with random real numbers between 1 and 2000 and print out the array in tabular format. Next, copy the values into a 1D array and sort the array. Display the median value. Finally, ask the user to enter a search value and output the results of both the linear search and the binary search. The search functions should return the first index that is found. Modify the search functions to allow a tolerance of +/- 1%. the language is c++.

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

int main()

{

int i,j,a,count=0,median,key,a[40][10],b[300],number[300];

printf("random numbers in a[40][10] ");

for (i=0; i<40;i++)

for (j=0; i<10;j++)

{

a[i][j]=rand() % 2000 + 1;

count++;

printf("%d ",a[i][j]);

for(k=0;k<=count;k++)

b[k]=a[i][j];

}

for(i=0;i<count;++i)

{

for(j=i+1;j<count;++j)

{

if(number[i]>number[j])

{

a=number[i];

number[i]=number[j];

number[j]=a;

}

}

}

printf("the numbers arranged in ascending order are given below ");

for(i=0;i<count;++i)

printf("%d ",number[i]);

if(count % 2 ==0)

median=(number[count/2]+number[count/2+1]/2.0;

else

median=number[count/2+1];

printf(" Median is %f ",median);

printf(" Enter the elements to be searched:");

scanf("%d",&key);

i=0;

while(i<count&&key!=a[i])

{

i++;

}

if(i<key)

{

printf("Number found at the location=%d",i+1);

}

else

{

printf("Number not found");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote