Print unit matrix using Array in C


This program is about print the two dimensional unit matrix using array.

Source Code

#include<stdio.h>
int main()
{
  int i,j,r,c,a[10][10];
  printf("\nEnter the Row Limit:");
  scanf("%d",&r);
  printf("\nEnter the Column Limit:");
  scanf("%d",&c);
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       if(i==j)
       {
         a[i][j]=1;
       }
       else
       {
         a[i][j]=0;
       }
    }
    printf("\n");
  }
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
      printf("\t%d",a[i][j]);
    }
    printf("\n");
  }
  return 0;
}
To download raw file Click Here

Output

Enter the Row Limit:3
Enter the Column Limit:3
1  0  0
0  1  0
0  0  1


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes