Product of diagonal elements of matrix by R4R Team

Matrix:
-Multidimensional Array
-Matrix consist of the rows and columns.

Syntax-
array[row][column]
//Martix with numbers of rows and columns

Diagonal of matrix:
condition: matrix must be sqaure matrix

Example-
matrix is:
1 2 3
4 5 6
7 8 9
Product of Diagonal elements is 45

program-

#include< stdio.h>
int main()
{
int a[10][10],r,c,i,j,pro=1;
printf("Enter rows and columns for Matrix\n");
scanf("%d%d",&r,&c);
//input in matrix
printf("Enter %d number in matrix\n",r*c);
for(i=0;i< r;i++)
{
for(j=0;j< c;j++){
scanf("%d",&a[i][j]);
}
}
//calculate Product of diagonal elements
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
if(i==j){
pro=pro*a[i][j];
}
}
}
printf("Product of diagonal elements is %d",pro);
}


output-

Enter rows and columns for Matrix
3 3
Enter 9 number in matrix
1 2 3 4 5 6 7 8 9
Product of diagonal elements is 45




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!