Write a program to find sum of right diagonals of a matrix.
#include<stdio.h>
int main()
{
int m, n, row, col, a[10][10], Sum = 0;
printf("Please Enter Number of rows and columns : ");
scanf("%d %d", &m, &n);
printf("\nPlease Enter the Matrix Elements\n");
for(row = 0; row < m; row++)
{
for(col = 0; col < n; col++)
{
scanf("%d", &a[row][col]);
}
}
for(row = 0; row < m; row++)
{
Sum = Sum + a[row][row];
}
printf("\nThe Sum of right diagonal elements of a Matrix = %d", Sum);
return 0;
}
#include<stdio.h>
int main()
{
int m, n, row, col, a[10][10], Sum = 0;
printf("Please Enter Number of rows and columns : ");
scanf("%d %d", &m, &n);
printf("\nPlease Enter the Matrix Elements\n");
for(row = 0; row < m; row++)
{
for(col = 0; col < n; col++)
{
scanf("%d", &a[row][col]);
}
}
for(row = 0; row < m; row++)
{
Sum = Sum + a[row][row];
}
printf("\nThe Sum of right diagonal elements of a Matrix = %d", Sum);
return 0;
}
একটি মন্তব্য পোস্ট করুন