Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to print a matrix of 0 and 1 as shown in description

Posted By: Sara Hughes     Category: C Programming     Views: 2341

PROGRAM TO PRINT FOLLOWING MATRIX.

1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1

Code for Program to print a matrix of 0 and 1 as shown in description in C Programming

#include<stdio.h>
#include<conio.h>

void main()
{
    int i,j,row,col,a[10][10];
    clrscr();

    printf("Enter the number of row ::  ");
    scanf("%d",&row);

    printf("Enter the number of column ::  ");
    scanf("%d",&col);

    if(row == col)
    {
        printf("\n");
        printf("Desired matrix is  \n\n");
        for(i=1;i<=row;i++)
        {
            printf("\n");
            for(j=1;j<=col;j++)
            {
                if (i == j)
                printf(" 1 ");
                else
                printf(" 0 ");
            }
        }
    }
    else
    printf("Must enter row and column equals  \n");
    getch();
}


/*
**********
OUTPUT
**********

Enter the number of row :: 9
Enter the number of column :: 9

Desired matrix is


1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1

*/
  
Share: 



Sara Hughes
Sara Hughes author of Program to print a matrix of 0 and 1 as shown in description is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!