Answer to Question #258203 in C for Hazzy

Question #258203

A game has three rounds and the scores of three rounds for two teams are stored in team1 and team2 arrays respectively.

Write a C program to do the following

  1. Create an array called team1 to store the scores of three rounds of team 1.
  2. Initialize the  team1 array with 8, 3, 7
  3. Create another array called team2 to store the scores of three rounds of team 2.
  4. Input the scores of three rounds of team 2 from the keyboard and store in the array.
  5. Display the winner of each round (team 1/ team 2) and overall winner (team which wins more rounds).
  6. Display the data stored in  team1 array, team2 array, winner of each round and overall winner.
1
Expert's answer
2021-10-28T14:17:53-0400
#include<stdio.h>
int main(){
	int team1[3] = {8,3,7};
	int team2[3];
	printf("Enter the three scores:\n");
	int n;
	for(n=0; n<3; n++){
		printf("Score %d:  ",(n+1));
		int b;
		
			scanf("%d", &b);
			team2[n] = b;
			
	}
	
	int i;
	
	for(i=0; i<3; i++){
		printf("Round %d:  ",(i+1));
		if(team1[i]>team2[i]){
			printf("  Winner is: %s\n", "team1");
		}
	 else	if(team1[i]<team2[i]){
			printf("Winner is: %s\n", "team2");
		}
		
	}
	int k,j;
	int sum_team1 = 0;
	int sum_team2 = 0;
	printf("Team 1----Team 2\n");
	for(k=0; k<3; k++){
		sum_team1 += team1[k];
	
		
	}
	
	for(j=0; j<3; j++){
		
		sum_team2 += team2[j];
		
	}
	int t;
	for(t=0; t<3; t++){
	printf("%d------------%d\n", team1[t], team2[t]);
	
	}
	
	if(sum_team1<sum_team2){
		printf("Overall winner is: %s\n", "team2");
	}
	
	if(sum_team1>sum_team2){
		printf("Overall winner is: %s\n", "team1");
	}
	
	
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS