Sunday, February 1, 2015

Matrix identity in C

#include<stdio.h>
int main(void)
{

//Create Matrix Identity
     int A[100][100],i,j; 
     for(i=0;i<5;i++)
     {
           for(j=0;j<5;j++)
           {
                 if(i==j)
                 {
                     A[i][j]=1;
                 }
                 else
                 {
                     A[i][j]=0;
                 }
           }
     }

//Print
    for(i=0; i<5; i++)
    {
        for(j=0; j<5; j++)
        {
        printf("\t %d",A[i][j]); 
        }
       printf("\n");
    }

}

No comments: