There are 2 soccer teams with the following statistics Write

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=(r and() % 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 dispat 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[]J);

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:

 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
 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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site