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

Summary of Project 3 . Write a C program create an array 115,000 CS501300 Projec

ID: 3702536 • Letter: S

Question

Summary of Project 3 . Write a C program create an array 115,000 CS501300 Projects (CS 50) Projects Prototype CS 50 F17303 2017-4F CS50 Proj3 (Arrays) 303 2017-..0x tudent NneProject 3 anple Size17 rray clements: with random numbers, find maximum, minimum, average, sort and find median, in that order. 8 12 75 98 53 57 81 14 27 80 67 72 37 87 74 73 16 Maximun-98. Hininun-10 verage54 0 12 14 75 90 53 5? 81 16 2? 80 6 72 3? 8 4 73 12 14 16 75 90 53 57 81 27 37 80 67 72 73 87 74 12 14 16 27 75 90 53 57 81 37 67 80 72 73 74 87 12 14 16 2? 3? 25 90 53 5? 81 6 72 80 23 74 8? 0 12 14 16 2? 3 53 75 90 5? 6? 81 72 73 80 74 8? 12 14 16 27 37 53 57 75 9 67 72 81 73 74 80 87 12 14 16 27 37 53 57 67 75 90 72 73 81 74 88 87 12 14 16 2? 37 53 57 6? 2 25 90 73 4 81 80 8? 0 12 14 16 2? 3 53 57 6? 72 73 75 96 24 80 81 8? 8 12 14 16 27 37 53 57 67 72 73 74 75 90 80 81 87 12 14 16 27 37 53 57 67 72 73 74 75 80 90 81 87 12 14 16 2? 3 53 5 6? 2 3 24 75 80 81 90 8? 0 12 14 16 27 37 53 57 6? 72 73 24 75 80 81 87 9G 12 14 16 27 37 53 57 67 72 73 74 75 80 81 87 90 12 14 16 27 37 53 57 67 72 73 74 75 80 81 87 90 12 14 16 2? 32 53 5 6? 2 23 24 75 80 81 87 9G 8 12 14 16 27 37 53 57 67 72 73 24 75 80 81 87 9G The array max size will have 20, however, each program run will work between 12 and 20 elements. Value of each element will be between 10 and 90. All project elements are integers Median-67

Explanation / Answer

#define _CRT_SECURE_NO_DEPRECATE

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

#define ARRAY_SIZE 20

#define UPPER_LIMIT 20

#define LOWER_LIMIT 12

#define DATA_UPPER_LIMIT 90

#define DATA_LOWER_LIMIT 10

//function declarations

void RandomizedPrint(int arr[], int size);

void PrintArray(int arr[], int size);

void findMaxMin(int arr[], int size);

void FindAverage(int arr[], int size);

void SortArrayBubble(int arr[], int size);

void FindMedian(int arr[], int size);

void BinSearch(int arr[], int size);

int main()

{

int sample[ARRAY_SIZE];

int sampleSize;

srand(time(NULL));

sampleSize = rand() % (UPPER_LIMIT - LOWER_LIMIT) + LOWER_LIMIT;

RandomizedPrint(sample, sampleSize);

findMaxMin(sample, sampleSize);

FindAverage(sample, sampleSize);

SortArrayBubble(sample, sampleSize);

FindMedian(sample, sampleSize);

//added by CheggEA to serach an element in an array

BinSearch(sample, sampleSize);

return 0;

}

//function definitions

void RandomizedPrint(int arr[], int size)

{

int i;

printf("Sample size: %d ", size);

printf("Array elements: ");

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

{

arr[i] = rand() % (DATA_UPPER_LIMIT - DATA_LOWER_LIMIT) + DATA_LOWER_LIMIT;

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

}

printf(" ");

}

void PrintArray(int arr[], int size)

{

int i;

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

{

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

}

printf(" ");

}

void findMaxMin(int arr[], int size)

{

int max, min,index;

//initialize max and min to first element

max = arr[0];

min = arr[0];

for (index = 0; index < size; index++)

{

if (max < arr[index])

{

max = arr[index];

}

if (min > arr[index])

{

min = arr[index];

}

}

printf("Max = %d, Min = %d ", max, min);

}

void FindAverage(int arr[], int size)

{

int index;

float avg,sum=0;

for (index = 0; index < size; index++)

{

sum += arr[index];

}

avg = sum / size;

printf("Average = %.2f ", avg);

}

void SortArrayBubble(int arr[], int size)

{

int i, j,tmp;

for (i = 0; i < size-1; i++)

{

for (j = 0; j < size - i - 1; j++)

{

if (arr[j] > arr[j + 1])

{

tmp = arr[j + 1];

arr[j + 1] = arr[j];

arr[j] = tmp;

}

}

PrintArray(arr, size);

}

}

void FindMedian(int arr[], int size)

{

int mid;

mid = size / 2;

//check if array size is odd or even

if (size % 2 == 1) //its odd,median is meddle element if sorted array

{

printf("Median is %d ", arr[mid]);

}

else //its even number , median is average of two middle elements

{

float constant = 2;

float med = (arr[mid] + arr[mid + 1])/constant ;

printf("Median is %.2f ", med);

}

}

//Added by CheggEA

void BinSearch(int arr[], int size)

{

int first = 0,last = size,mid;

int search;

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

scanf("%d", &search);

while (first <= last)

{

mid = (first + last) / 2;

if (arr[mid] < search)

first = mid + 1;

else if(arr[mid] == search)

{

printf("%d found at location %d. ", search, mid+1);

break;

}

else

{

last = mid - 1;

}

}

if (first > last)

printf("Not found!! %d isn't present in the list. ", search);

}

/*output

Sample size: 19

Array elements:

67 24 40 63 21 22 28 29 77 66 54 38 79 56 18 68 74 22 39

Max = 79, Min = 18

Average = 46.58

24 40 63 21 22 28 29 67 66 54 38 77 56 18 68 74 22 39 79

24 40 21 22 28 29 63 66 54 38 67 56 18 68 74 22 39 77 79

24 21 22 28 29 40 63 54 38 66 56 18 67 68 22 39 74 77 79

21 22 24 28 29 40 54 38 63 56 18 66 67 22 39 68 74 77 79

21 22 24 28 29 40 38 54 56 18 63 66 22 39 67 68 74 77 79

21 22 24 28 29 38 40 54 18 56 63 22 39 66 67 68 74 77 79

21 22 24 28 29 38 40 18 54 56 22 39 63 66 67 68 74 77 79

21 22 24 28 29 38 18 40 54 22 39 56 63 66 67 68 74 77 79

21 22 24 28 29 18 38 40 22 39 54 56 63 66 67 68 74 77 79

21 22 24 28 18 29 38 22 39 40 54 56 63 66 67 68 74 77 79

21 22 24 18 28 29 22 38 39 40 54 56 63 66 67 68 74 77 79

21 22 18 24 28 22 29 38 39 40 54 56 63 66 67 68 74 77 79

21 18 22 24 22 28 29 38 39 40 54 56 63 66 67 68 74 77 79

18 21 22 22 24 28 29 38 39 40 54 56 63 66 67 68 74 77 79

18 21 22 22 24 28 29 38 39 40 54 56 63 66 67 68 74 77 79

18 21 22 22 24 28 29 38 39 40 54 56 63 66 67 68 74 77 79

18 21 22 22 24 28 29 38 39 40 54 56 63 66 67 68 74 77 79

18 21 22 22 24 28 29 38 39 40 54 56 63 66 67 68 74 77 79

Median is 40

Enter the number to be searched : 54

54 found at location 11.

//one more output

Sample size: 13

Array elements:

41 21 68 52 48 85 21 59 89 33 32 16 61

Max = 89, Min = 16

Average = 48.15

21 41 52 48 68 21 59 85 33 32 16 61 89

21 41 48 52 21 59 68 33 32 16 61 85 89

21 41 48 21 52 59 33 32 16 61 68 85 89

21 41 21 48 52 33 32 16 59 61 68 85 89

21 21 41 48 33 32 16 52 59 61 68 85 89

21 21 41 33 32 16 48 52 59 61 68 85 89

21 21 33 32 16 41 48 52 59 61 68 85 89

21 21 32 16 33 41 48 52 59 61 68 85 89

21 21 16 32 33 41 48 52 59 61 68 85 89

21 16 21 32 33 41 48 52 59 61 68 85 89

16 21 21 32 33 41 48 52 59 61 68 85 89

16 21 21 32 33 41 48 52 59 61 68 85 89

Median is 48

Enter the number to be searched : 90

Not found!! 90 isn't present in the list.

*/

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