There are 2 soccer teams with the following statistics. Write a program which do
ID: 3935757 • Letter: T
Question
There are 2 soccer teams with the following statistics. Write a program which does the following 4 tasks: The tables shown above are examples Write a function stores the statistics in a 2-dimensional array The number of matches, goals and yellow cards are obtained using the following lines Number of matches= (rand() % 10) + 1 i.e. Number of matches are between 1 and 10 Goals scored=(rand() % 6) + 1 i.e. Number of goals scored are between 1 and 6 Yellow cards=(r and() % 4) + 1 i.e. Number of yellow cards are between 1 and 4 The function prototype would be as follows: void fillarray(int a[][3]); Write a function which displays the two arrays. The function prototype would be void displays ray(int a[][3]); Write a function which calculates the goals per game for each player and stores them in an array Function prototype would be: void avgarray(int a[][3], float b[]);Explanation / Answer
Following is the required code in C
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void fillarray( int a[][3] ){
int length = sizeof( a )/sizeof( a[0] );
printf("%d ", length);
int i = 0;
for(; i < length; i++){
a[i][0] = (rand()%10 ) + 1;
a[i][1] = (rand()%6) + 1;
a[i][2] = (rand()%4) + 1;
}
}
void disparray( int a[][3] ){
int length = sizeof(a)/sizeof( a[0] );
printf("%d ", length);
printf("Player Matches Played Goals Yellow cards ");
int i = 0;
for(; i < length; i++){
printf("%d %d %d %d ", i+1, a[i][0], a[i][1], a[i][2] );
}
}
void avgarray( int a[][3], float b[] ){
int length = sizeof(a)/sizeof( a[0] );
int i = 0;
for(; i < length; i++){
b[i] = (a[i][1]*1.0)/a[i][0];
}
}
int main(){
int a[4][3];
fillarray( a );
disparray( a );
float b[4];
avgarray(a,b);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.