Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
797 B
9
Indexable
Never
#include <stdio.h>
#include <math.h>
#define MAX 50


int main(){
	int a[MAX][MAX],b[MAX][MAX],m,n,i,j;
	printf ("Nhap so hang va cot cua ma tran a: ");
	scanf ("%d",&n);
	for (i=0; i<n; i++){
		for (j=0; j<n; j++){
			printf("Nhap phan tu a[%d][%d] : ",i+1,j+1);
			scanf("%d",&a[i][j]);
		}
	}
	printf("\n");
	printf("\nMa tran vua nhap la : \n");
   	for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
         printf("%d\t", a[i][j]);
      }
      printf("\n");
   }
   printf("\n");
   float sum=0;
   int dem = 0;
   for (i=0; i<n; i++){
		for (j= n-i; j<n; j++){
			if(a[i][j] > 0) {
				sum+=a[i][j];
				dem++;
			}
		}
	}
	printf("Trung binh cong cac phan tu duong nam phia duoi duong cheo phu la : %f",sum/dem);
	printf("/n");
	return 0;
}