There are 2 soccer teams with the following statistics Write
Solution
#include <stdio.h>
#include <stdlib.h> //header file which is needed for rand() function
void fillarray(int a[][3]) //fill the array with random numbers
{
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
a[0][j] = (rand()%10) +1;
a[1][j] = (rand()%6) +1;
a[2][j] = (rand()%4)+1;
}
}
void disparray(int a[][3]) //function to display array
{
int i,j;
printf(\"Player\\tMatchesPlayed\\tGoals\\tYellowCards\ \");
for(i=0;i<3;i++)
{
printf(\"%d\\t\\t\",i+1);
for(j=0;j<3;j++)
{
printf(\"\\t%d\\t\\t\",a[i][j]);
}
printf(\"\ \");
}
}
void avgarray(int a[][3],int b[3]) //calculate the averages
{
int i,j;
b[0]=b[1]=b[2]=0;
for(i=0;i<3;i++)
{
b[0] = b[0] + a[i][0];
b[1] = b[1] + a[i][1];
b[2] = b[2] + a[i][2];
}
// printf(\"%d %d %d\ \",b[0],b[1],b[2]);
printf(\"\ Average matches: %d\",b[0]/3);
printf(\"\ Average Goals: %d\",b[1]/3);
printf(\"\ Average Yellow Cards: %d\",b[2]/3);
}
int main(void)
{
int a[3][3],b[3];
fillarray(a);
disparray(a);
avgarray(a,b);
return 0;
}
output:

