# C Programming – HackerRank Solution | 2D ARRAYS- Indian Badminton Association |

### (HackerRank) Write a Modular C Programming code to solve 2D ARRAYS- Indian Badminton Association, Indian Badminton Association has N International badminton players.

Indian Badminton Association has N International badminton players. During the year 2015-2020 each of them played M matches.

For each player and for each match read the outcome of that match (Enter ‘W’ if the player won the match. Enter ‘L’ if the player lost the match).

Display how many matches won by each player. Apply Problem Solving Framework to solve the problem.

Input Format

First line is N players and M matches played by each player

Constraints

Outcome of the match is either W or L.

N>0 and M>0.

Output Format

Display all players total matches won.

Sample Input 0

```2 4
W W W L
L L W W
```

Sample Output 0

```Player 1 won 3 matches
Player 2 won 2 matches
```

Sample Input 1

```0 -2
```

Sample Output 1

`Invalid players and matches`

CODE:

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

int main() {
int matches,players;
scanf("%d%d",&players,&matches);
if(matches>0 && players>0)
{
char outcome[players][matches];
int win_sum;
for(int i=0;i<players;i++)
{
win_sum=0;
for(int j=0;j<matches;j++)
{
scanf(" %c ",&outcome[i][j]);
if(outcome[i][j]=='W' || outcome[i][j]=='w')
win_sum++;
}
printf("Player %d won %d matches\n",i+1,win_sum);
}
}
else{
printf("Invalid players and matches");
}

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)

2 4
W W W L
L L W W

Player 1 won 3 matches
Player 2 won 2 matches
Expected Output

Player 1 won 3 matches
Player 2 won 2 matches
Interview Prep | B```

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

Top 100+ C Programming codes – KLE Technological University