
Function Call Diagram
Write a function call diagram showing this program.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// function sum() -> Returns the sum of the elements of the array
int sum(int array[]) {
int i, sum = 0;
for(i = 0; i < 5; i++) {
sum += array[i]; // Summing up the elements
}
return sum; // Returning the sum
}
// function average() -> Returns the average of an array
float average(int array[]) {
int tot;
float avg;
tot = sum(array); // Calling the function sum() -> To get the sum of the elements of the array
avg = tot / 5.0; // Computing the average
return avg; // Returning the average
}
int main() {
int a[5][5]; // 2-D array
int i, j;
int row[5]; // To store each row of the 2-D array
float avg[5]; // To store the average of each of the 5 rows of the 2-D array
int d1[5], d2[5]; // To store the diagonals of the 2-D array
int sumD1, sumD2; // To store the sum of the 2 diagonals of the 2-D array
srand(time(0));
for(i = 0; i < 5; i++) {
for(j = 0; j < 5; j++) {
a[i][j] = (rand() % 10) + 1; // Storing random integers in the 2-D array
}
}
for(i = 0; i < 5; i++) {
for(j = 0; j < 5; j++) {
row[j] = a[i][j]; // Filling array- row with each row of the 2-D array
}
avg[i] = average(row); // Computing the average of each row by calling the function average() -> To get the average of the row
}
for(i = 0; i < 5; i++) {
for(j = 0; j < 5; j++) {
if(i == j)
d1[i] = a[i][j]; // Filling the diagonal array
if((i + j) == 4)
d2[i] = a[i][j]; // Filling the diagonal array
}
}
sumD1 = sum(d1); // Calling the function sum() -> To get the sum of the elements of the diagonal
sumD2 = sum(d2); // Calling the function sum() -> To get the sum of the elements of the diagonal
printf(" \t \t \t \t \tAverage\n");
for(i = 0; i < 5; i++) {
for(j = 0; j < 5; j++) {
printf("%d\t", a[i][j]); // Displaying elements of the row
}
printf("%.1f\n", avg[i]); // Displaying the average of the row
}
// Displaying the greater diagonal
if(sumD1 < sumD2) {
printf("\nThe top right to bottom left diagonal's total is greater and the value is %d.", sumD2);
} else if(sumD1 > sumD2){
printf("\nThe top top left to bottom right diagonal's total is greater and the value is %d.", sumD1);
} else {
printf("\nNo diagonal is greater. The values are %d and %d.", sumD1, sumD2);
}
return 0;
}

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- When calling a function, what exactly does it imply to say that you need the "base address of an array"?arrow_forwardC++arrow_forwardTask - Using pointers to process arrays (C Language) Example #5 below expected output is 45, but from the program below its coming out to 46. Please help make it come out to 45 as expected In a TV show, each minute can be either interesting or boring. Assume that if 7 consecutive minutes are boring, then an average viewer will stop watching the show. Write a C program that calculates how many minutes that an average viewer will watch a TV show, given the interesting minutes. Assume the TV shows are 45 minutes long. Requirements Name your program project4_minutes.c. Follow the format of the examples below. The program will read in the number of interesting minutes, then read in the interesting minutes. The program should include the following function. Do not modify the function prototype. int find_minute(int *minutes, int n); minutes represents the input array for interesting minutes, n is the length of the array (the number of interesting minutes). The function returns the how…arrow_forward
- Task- Median elements (C Language) Example #4 expected output is 5, but from the program below its coming out to 4. Please help make it come out to 5 as expected Given an array of integer elements, the median is the value that separates the higher half from the lower half of the values. In other words, the median is the central element of a sorted array. Since multiple elements of an input array can be equal to the median, in this task you are asked to compute the number of elements equal to the median in an input array of size N, with N being an odd number. Requirements Name your program project4_median.c. Follow the format of the examples below. The program will read the value of N, then read in the values that compose the array. These values are not necessarily sorted. The program should include the following function. Do not modify the function prototype. int compute_median(int *a, int n); a represents the input array, n is the length of the array. The function returns the…arrow_forward1- Write a user-defined function that accepts an array of integers. The function should generate the percentage each value in the array is of the total of all array values. Store the % value in another array. That array should also be declared as a formal parameter of the function. 2- In the main function, create a prompt that asks the user for inputs to the array. Ask the user to enter up to 20 values, and type -1 when done. (-1 is the sentinel value). It marks the end of the array. A user can put in any number of variables up to 20 (20 is the size of the array, it could be partially filled). 3- Display a table like the following example, showing each data value and what percentage each value is of the total of all array values. Do this by invoking the function in part 1.arrow_forwardC++ Coding: ArraysTrue and False Code function definitions for eoNum() and output(): Both eoNum() and output() are recursive functions. output() stores the even/odd value in an array. Store 0 if the element in the data array is even and store 1 if the element in the data array is odd. eoNum() displays all the values in an array to the console.arrow_forward
- C++arrow_forwardMULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS HANDS-ON use #include<stdio.h>arrow_forwardMIPS Assembly The program: Write a function in MIPS assembly that takes an array of integers and finds local minimum points. i.e., points that if the input entry is smaller than both adjacent entries. The output is an array of the same size of the input array. The output point is 1 if the corresponding input entry is a relative minimum, otherwise 0. (You should ignore the output array's boundary items, set to 0.) My code: # (Note: The first/last entry of the output array is always 0# since it's ignored, never be a local minimum.)# $a0: The base address of the input array# $a1: The base address of the output array with local minimum points# $a2: Size of arrayfind_local_minima:############################ Part 2: your code begins here ###la $t1, ($t2)la $t1, ($t2)move $a1, $s0 li $a2, 4jal find_local_minima print:ble $a2, 0, exitlw $a0, ($s0)li $v0, 1syscall addi $s0, $s0, 4addi $a2, $a2, -1 ############################ Part 2: your code ends here ###jr $ra I am not getting the correct…arrow_forward
- Please complete the following guidelines and hints. Using C language. Please use this template: #include <stdio.h>#define MAX 100struct cg { // structure to hold x and y coordinates and massfloat x, y, mass;}masses[MAX];int readin(void){/* Write this function to read in the datainto the array massesnote that this function should return the number ofmasses read in from the file */}void computecg(int n_masses){/* Write this function to compute the C of Gand print the result */}int main(void){int number;if((number = readin()) > 0)computecg(number);return 0;}Testing your workTypical Input from keyboard:40 0 10 1 11 0 11 1 1Typical Output to screen:CoG coordinates are: x = 0.50 y = 0.50arrow_forwarduse c++ Programming language Write a program that creates a two dimensional array initialized with test data. Use any data type you wish . The program should have following functions: .getAverage: This function should accept a two dimensional array as its argument and return the average of each row (each student have their average) and each column (class test average) all the values in the array. .getRowTotal: This function should accept a two dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the total of the values in the specified row. .getColumnTotal: This function should accept a two dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The function should return the total of the values in the specified column. .getHighestInRow: This function should accept a two…arrow_forwardWhat does the phrase "base address of an array" relate to, and how does it come to be utilized in a call to a function?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





