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
#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");
}
}
Comments
Leave a comment