C Programming – HackerRank Solution | 2D ARRAYS – Indian Cricket team |

Write a Modular C Programming code to solve 2D ARRAYS – Indian Cricket team, Display the total runs scored by each player and find the player with highest total runs scorer

Indian Cricket team is doing so well in all 3 formats: (1) 20-20 2) ODI 3) TEST) -of the game. They are number 1 in Test Rankings. Rohit Sharma and Rahul Dravid are leading the team well.

Consider currently Indian squad has N players and read the runs scored by each of them in 20-20, ODI and TEST matches respectively. Display the total runs scored by each player and find the player with the highest total runs scorer.

Apply Problem Solving Framework to solve the above problem.

Input Format

First line indicates N players and 3 formats of game.

Constraints

N >5

formats = 3

Output Format

Display total runs of all the players.

Display player number with highest total runs scorer.

Sample Input 0

6 3
324 455 777
345 3433 643
2345 7533 324
564 232 454
343 545 333
666 733 22

Sample Output 0

324 455 777
345 3433 643
2345 7533 324
564 232 454
343 545 333
666 733 22

Player 1: 1556
Player 2: 4421
Player 3: 10202
Player 4: 1250
Player 5: 1221
Player 6: 1421

Player 3 has highest total runs scored of 10202

Sample Input 1

5 2

Sample Output 1

Invalid players or game formats

Sample Input 2

10 5

Sample Output 2

Invalid players or game formats

Refer : C Programming HackerRank all solutions for Loops | Arrays | strings

 

CODE:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

void read(int a[30][30],int n,int m)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
}
void display(int a[30][30],int n,int m)
{
    int i,j,sum[30]={0},max=0,s=0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
           {
            printf("%d ",a[i][j]);
             sum[i]=sum[i]+a[i][j];
            }
        printf("\n");
    }
    printf("\n");
     for(i=0;i<n;i++) 
{ 
printf("Player %d: %d \n",i+1,sum[i]);
 if(sum[i]>max)
         {
            max=sum[i];
             s=i;
         }
    }    
    printf("\nPlayer %d has highest total runs scored of %d",s+1,max);
}
int main() {
int n,m,a[30][30];
    scanf("%d%d",&n,&m);
    if(n>5&&m==3)
    {
     read(a,n,m);
    display(a,n,m);   
    }
    else 
        printf("Invalid players or game formats\n");
    return 0;
}

OUTPUT

Congratulations, you passed the sample test case.

Click the Submit Code button to run your code against all the test cases.

Input (stdin)

6 3
324 455 777
345 3433 643
2345 7533 324
564 232 454
343 545 333
666 733 22
Your Output (stdout)

324 455 777 
345 3433 643 
2345 7533 324 
564 232 454 
343 545 333 
666 733 22 

Player 1: 1556 
Player 2: 4421 
Player 3: 10202 
Player 4: 1250 
Player 5: 1221 
Player 6: 1421 

Player 3 has highest total runs scored of 10202
Expected Output

324 455 777
345 3433 643
2345 7533 324
564 232 454
343 545 333
666 733 22

Player 1: 1556
Player 2: 4421
Player 3: 10202
Player 4: 1250
Player 5: 1221
Player 6: 1421

Player 3 has highest total runs scored of 10202

 

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!