There are two parts. 1. Write code for a function that receives two parameters (a,and b) by value and has two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). From main, use scanf to get two numbers, then call the function, and then display both returned values to the output in a printf statement. 2. After part 1 is completed, write code to get 20 integer numbers from the user. The code then displays how many of those numbers are above the numbers average. To get proper credit you must follow these steps: a. write a for loop to fill the array with numbers from the user. Use a pointer b. use an index to pass through all array elements to calculate the average in another loop. c. write a function, then pass the array, its size, and the average to the function. The function returns the count of the number of elements that are above the average.

The first part of the assignment requires writing code for a function that takes in two parameters, “a” and “b,” by value, and two parameters, “c” and “d,” by reference. All parameters are of type double. The task of the function is to assign “c” the value of “a” divided by “b” and assign “d” the value of “a” multiplied by “b.” Subsequently, the main function should utilize the scanf function to obtain two numbers from the user, call the aforementioned function, and display both returned values using the printf function.

To accomplish this, we can define a function called “calculateValues” that takes in four parameters: two doubles, “a” and “b,” passed by value, and two double pointers, “c” and “d,” passed by reference. Within the function, we assign the value of “a” divided by “b” to “c” using the assignment operator (=), and the value of “a” multiplied by “b” to “d” using the same assignment operator.

The code for the above function would look as follows:

“`c
void calculateValues(double a, double b, double* c, double* d) {
*c = a / b;
*d = a * b;
}
“`

In the main function, we can use the scanf function to obtain two double values from the user and store them in variables “num1” and “num2.” We then declare two double variables, “result1” and “result2,” to store the returned values from the function “calculateValues.” After calling the function, we can use the printf function to display the values of “result1” and “result2”.

“`c
int main() {
double num1, num2;
printf(“Enter two numbers: “);
scanf(“%lf %lf”, &num1, &num2);

double result1, result2;
calculateValues(num1, num2, &result1, &result2);

printf(“The value of c is: %lfn”, result1);
printf(“The value of d is: %lfn”, result2);

return 0;
}
“`

For the second part of the assignment, we are required to obtain 20 integer numbers from the user and then display the count of how many of those numbers are above the average. To accomplish this, we can follow the provided steps:

a. We need to write a for loop to fill an array with the numbers entered by the user. We can create an integer array called “numbers” with a size of 20 and use a pointer to navigate through its elements. Inside the loop, we can use scanf to get the numbers from the user and store them in the array.

“`c
int numbers[20];
int* ptr = numbers;

for (int i = 0; i < 20; i++) { printf("Enter a number: "); scanf("%d", ptr++); } ``` This loop will prompt the user to enter a number, and each entered number will be stored in the array using the incremented pointer. b. Next, we need to calculate the average of the numbers stored in the array. We can do this by using another loop that iterates through all the elements of the array and adds their values to a sum variable. After the loop, we divide the sum by the total number of elements (20 in this case) to obtain the average. ```c int sum = 0; for (int i = 0; i < 20; i++) { sum += numbers[i]; } double average = (double)sum / 20; ``` Since we are dealing with integer values, we need to cast the sum variable to a double before dividing it by the total number of elements to ensure accurate division. c. Lastly, we can define a function called "countAboveAverage" that takes in the array, its size, and the average as parameters. This function loops through the array elements and counts the number of elements that are above the average. Finally, it returns the count. ```c int countAboveAverage(int* arr, int size, double avg) { int count = 0; for (int i = 0; i < size; i++) { if (arr[i] > avg) {
count++;
}
}
return count;
}
“`

This function compares each element to the average and increments the count variable if the element is larger. The final count is then returned.

To complete the assignment, we can call the “countAboveAverage” function with the array, its size (20), and the calculated average as arguments. The function’s returned value can then be displayed using the printf function.

“`c
int main() {
// Code for filling the array and calculating the average as explained above.

int aboveCount = countAboveAverage(numbers, 20, average);
printf(“The count of numbers above the average is: %dn”, aboveCount);

return 0;
}
“`

This program will prompt the user to enter 20 numbers, calculate their average, and display the count of numbers that are above the average.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer