Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

print diagonal elements of matrix in c

#include <stdio.h>
 
#define MAXROW      10
#define MAXCOL      10
 
int main()
{
    int matrix[MAXROW][MAXCOL];
    int i,j,r,c;
     
    printf("Enter number of Rows :");
    scanf("%d",&r);
    printf("Enter number of Cols :");
    scanf("%d",&c);
 
    printf("
Enter matrix elements :
");
    for(i=0;i< r;i++)
    {
        for(j=0;j< c;j++)
        {
            printf("Enter element [%d,%d] : ",i+1,j+1);
            scanf("%d",&matrix[i][j]);
        }
    }
 
    /*check condition to print diagonals, matrix must be square matrix*/
    if(r==c)
    {
            /*print diagonals*/
            for(i=0;i< c;i++)
            {
                for(j=0;j< r;j++)
                {
 
                    if(i==j)
                        printf("%d	",matrix[j][i]);    /*print elements*/
                    else
                        printf("	");   /*print space*/
                }
                printf("
");   /*after each row print new line*/      
            }
    }
    else
    {
        printf("
Matrix is not a Square Matrix.");
    }
    return 0;   
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: 2d array of strings and ints python 
Typescript :: .setRowHeights google script 
Typescript :: fusion builder elegant elements for free 
Typescript :: "gcm_sender_id":"15057814354" 
Typescript :: tiqets endpoints 
Typescript :: typescript find in all words 
Typescript :: UpdateTable operation with the GlobalSecondaryIndexUpdates parameter 
Cpp :: arduino uno hello world 
Cpp :: ‘setprecision’ was not declared in this scope 
Cpp :: sfml local mouse position 
Cpp :: qstring mid 
Cpp :: flutter datetime format 
Cpp :: how to complie with c++ 17 
Cpp :: ue4 spawn actor c++ 
Cpp :: maximum in vector 
Cpp :: how to use sleep function in c++ windows 
Cpp :: for loop vector 
Cpp :: how to append one vector to another c++ 
Cpp :: inserting at start in vector c++ 
Cpp :: cv2.threshold c++ 
Cpp :: ue4 find component c++ 
Cpp :: matrix layout in C++ 
Cpp :: compile notepad++ c++ 
Cpp :: c++ split long code 
Cpp :: c++ remove whitespace from string 
Cpp :: finding no of unique characters in a string c++ 
Cpp :: how to print with the bool value in cpp 
Cpp :: c++ check if string contains non alphanumeric 
Cpp :: c++ check if string contains uppercase 
Cpp :: how to get a letter from the users string in c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =