#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define max 5
int mat[max][max];
void main()
{
int i,j;
int row_sum[max];
int col_sum[max];
int mat_sum = 0;
clrscr();
randomize();
printf("\n\n RANDOM MATRIX \n\n");
for(i=0;i<max;i++)
{
row_sum[i] = 0;
printf("\n");
for(j=0;j<max;j++)
{
if(i==0)
col_sum[j] = 0;
mat[i][j] = random(10);
col_sum[j] += mat[i][j];
row_sum[i] += mat[i][j];
mat_sum += mat[i][j];
printf(" %d",mat[i][j]);
}
}
getch();
printf("\n\n Row Sums");
for(i =0; i<max; i++)
printf("\n Row %d = %d",i+1,row_sum[i]);
printf("\n\n Column Sums");
for(i =0; i<max; i++)
printf("\n Column %d = %d",i+1,col_sum[i]);
printf("\n\n Matrix Sum = %d",mat_sum);
getch();
}
No comments:
Post a Comment