C Programming – HackerRank Solution | 2D ARRAYS- Rinku’s Sudoku square

Write a Modular C Programming code to solve 2D ARRAYS- Rinku’s Sudoku square | to identify whether the square is Rinku’s Sudoku square.

Rinku was reading a newspaper one-day morning. She came across a Sudoku game where she tried to solve it in a different way. For a N x N Sudoku game, she adds up all the column-wise numbers. If all the column-wise sums are equal, then she called it Rinku’s Sudoku square.

Apply a problem-solving framework and write a modular C program to identify whether the square is Rinku’s Sudoku square.

Input Format

N – indicates the Size of the Sudoku square.

Constraints

Rows and columns should be equal.

Output Format

Display a message whether Sudoku square is Rinku’s Sudoku square.

Sample Input 0

4
4 3 6 5
8 7 2 1
5 6 3 4
1 2 7 8

Sample Output 0

Sudoku square is Rinku's Sudoku square.

Sample Input 1

3
3 2 5
6 4 8
10 8 9

Sample Output 1

Sudoku square is not a Rinku's Sudoku square.

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 n,int a[n][n])
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
scanf("%d",&a[i][j]);}
    }
}

void sukodu(int n,int a[n][n])
{
    int su[n],stat=0;
for(int i=0;i<n;i++)
{  
    int sum=0;
    for(int j=0;j<n;j++)
    {
sum+=a[i][j];
    }
    su[i]=sum;
}
 
 for(int l=0;l<n;l++) { if(l!=n-1) { if(su[l]==su[l+1]) { stat=1; } else { stat=0; break; } } } if(stat==1) printf("Sudoku square is Rinku's Sudoku square.\n"); else if(stat==0) printf("Sudoku square is not a Rinku's Sudoku square.\n"); } int main() { int n; scanf("%d",&n); if(n>0)
    {
        int a[n][n];
        read(n,a);
        sukodu(n,a);
    }
    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)

4
4 3 6 5
8 7 2 1
5 6 3 4
1 2 7 8
Your Output (stdout)

Sudoku square is Rinku's Sudoku square.
Expected Output

Sudoku square is Rinku's Sudoku square.

 

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