Identity Matrix

Easy 2D Arrays (Matrices)
Solve in Playground →

Problem Statement

Write a C program to check whether a given square matrix N x N is an Identity Matrix.

Input Format

First line: N. Then N lines of N integers.

Output Format

Print 'Yes' if it is an Identity Matrix, otherwise 'No'.

Constraints

1 <= N <= 10

Sample Input

3
1 0 0
0 1 0
0 0 1

Sample Output

Yes

Explanation

Diagonal elements are 1 and all off-diagonal elements are 0.

Starter Code

#include <stdio.h>

int main() {
    int n;
    if (scanf("%d", &n) == 1) {
        int a[n][n];
        for(int i=0; i<n; i++) for(int j=0; j<n; j++) scanf("%d", &a[i][j]);
        // Write your code here
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used