Need help with C Programming Homework please There are 2 soc

Need help with C Programming Homework please!

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 that stores the statistics m a 2-dimeusional 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 = (rand() % 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 disparray(int a[][3]); Write a function which calculates the goals per game for each player and stores them in an array. For e.g. First element m b for team 1 would be team 1 [0][1] team 1[0][0]. Function prototype would be: void avgarray(int a[][3). float b[]); Compute the average of goals per game for each team and display which one is better. Also display the team which has fewer total of yellow cards. (This task can be done without a function) Don\'t forget to add this line in main() before you declare the variables. This line is for the functioning of rand() function. You are not expected to know how this line or rand() function works. (time(NULL))

Solution

Ans:

#include<stdio.h>
#include<stdlib.h>
void fillarray(int a[][3]);
void disparray(int a[][3]);
void avgarray(int a[][3],float b[]);
int main()
{
int team1[3][3];//used to store statistics of first soccer team
int team2[3][3]; //used to store statistics of second soccer team
float team1_avg[3]; //used to store goals per game of first arry
float team2_avg[3]; //used to store goals per game of second array
int team1_total_goals; //total goals scored by team1
int team2_total_goals; //total goals scored by team2
int team1_total_matches; //total matches played by team1
int team2_total_matches; //total mathces played by team2
int team1_total_yellow_cards; //total yellow cards of team1
int team2_total_yellow_cards; //total yellow cards of team2
float team1_goals_avg;
float team2_goals_avg;
srand(time(NULL));
fillarray(team1);//to read values in to first array
fillarray(team2);//to read values in to second array
printf(\"First soccer team details \ \");
printf(\"Matchesplayed\\tGoals \\t YellowCards\ \");
disparray(team1);//used to display first array
printf(\"Second soccer team details \ \");
printf(\"Matchesplayed\\tGoals \\t YellowCards\ \");
disparray(team2); //used to display second array
avgarray(team1,team1_avg);//used to calculate goals per game for first array
avgarray(team2,team2_avg);//used to calculate goals per game for second array

//average of goals per game for each team
team1_total_goals=team1[0][1]+team1[1][1]+team1[2][1];
team2_total_goals=team2[0][1]+team2[1][1]+team2[2][1];

team1_total_matches=team1[0][0]+team1[1][0]+team1[2][0];
team2_total_matches=team2[0][0]+team2[1][0]+team2[2][0];

team1_goals_avg=(float)team1_total_goals/team1_total_matches;
team2_goals_avg=(float)team2_total_goals/team2_total_matches;
printf(\"Average of goals per game for Team1=%f\ \",team1_goals_avg);
   printf(\"Average of goals per game for Team2=%f\ \",team2_goals_avg);
if(team1_goals_avg>team2_goals_avg)
   printf(\"Team1 is better\ \");
else
   printf(\"Team2 is better\ \");

team1_total_yellow_cards=team1[0][2]+team1[1][2]+team1[2][2];
team2_total_yellow_cards=team2[0][2]+team2[1][2]+team2[2][2];
printf(\"Total Yellow cards of Team1=%d\ \",team1_total_yellow_cards);
printf(\"Total Yellow cards of Team2=%d\ \",team2_total_yellow_cards);
if(team1_total_yellow_cards<team2_total_yellow_cards)
printf(\"Team1 has fewer yellow cards\");
else
printf(\"Team2 has fewer yellow cards\");


return 0;
}
void fillarray(int a[][3]) //used to fill details
{
int i,j;
for(i=0;i<3;i++)
{
    a[i][0]=(rand()%10)+1;//Number of matches
    a[i][1]=(rand()%6)+1;//Number of goals scored
    a[i][2]=(rand()%4)+1;//Number of Yellow cards
} //end of for loop
}//end of fillarray
void disparray(int a[][3]) //used to display result
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
    printf(\"%d\\t\\t\",a[i][j]);
}
printf(\"\ \");
}//end of outer for loop
}//end of disparray
void avgarray(int a[][3],float b[])//to calculate goals per game
{
int i;
for(i=0;i<3;i++)
{
b[i]=a[i][1]/a[i][0];
}
}//end of avgarray

Need help with C Programming Homework please! There are 2 soccer teams with the following statistics. Write a program which does the following 4 tasks: The tabl
Need help with C Programming Homework please! There are 2 soccer teams with the following statistics. Write a program which does the following 4 tasks: The tabl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site