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

2018) of average), except that instead of each of the data points some data poin

ID: 3705706 • Letter: 2

Question

2018) of average), except that instead of each of the data points some data points of a non-em as: arithmetic mean is similar to an ordinary arithmetic mean (the mst comm contribute more than others based on their weights. Formally,heus defined contributing equally to the pty set of data (???" }having weights (wo-WyWyWp ) is defined is the weighted arithmetic mean of the elements in the array - which is equivalent to: (Wo. Wy, Wa,Wy, Ww-1) are the weights Create a program that computes the weighted average of an array of N elements following the constrains specified below: Ask the user to input the number of elements N you will store in the array Create a function that receives N, creates an array element to a random number between 0 and 100 (inclusive). This function must return the array, Call this function in your main function to initialize an array of integer called numbers - of N integer elements and initializes each - Create a function that receives N, creates an array of N double elements and initialize each element to a random floating-point number between 0.0 and 1.0. This function must returr the array. Call this function in the main function to initialize an array of floating poin numbers called weights. - Create a function that receives an array of integer numbers, an array of floating-point wei and outputs the weighted arithmetic mean, Call this function in the main function to conm the weighted arithmetic mean of your variable numbers using weights. Hint: verify what happens if you build a fraction where the numerator is a random number between 0-100 and denominator is always 100. Use this idea to generate a random tloating-point number between 0.0 and 1.0 - Print out the weighted arithmetic mean. - ewaanC)

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

#include<time.h>

int getRandom(int lower, int upper)

{

int num = (rand() + lower) % (upper + 1);

// printf("%d ",num);

return num;

}

void fillNumbers(int *numbers,int number)

{

int i=0;

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

{

numbers[i]=getRandom(0,100);

}

}

void fillWeights(double *weights,int number)

{

int i=0;

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

{

weights[i]=(double)getRandom(0,100)/100;

}

}

int main()

{

int number;

//printf("Enter an number: ");  

  

scanf("%d", &number);

int numbers[number];

double weights[number];

srand(time(0));

fillNumbers(numbers,number);

fillWeights(weights,number);

int i=0;

int total=0;

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

total+=(numbers[i]*weights[i]);

//printf("total = %d ",total);

int avg=total/number;

printf("Average = %d",avg);

  

}

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