Advertisement
toantranct

loz

Jun 7th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main() {
  5.     /*
  6.     Vi?t chuong trình du?i d?ng hàm th?c hi?n các ch?c nang sau:
  7.  
  8. 1.       Nh?p ma tr?n g?m mxn ph?n t? có ki?u nguyên.
  9. 2.      Hi?n th? ma tr?n v?a nh?p ra màn hình theo d?ng b?ng.
  10. 3.      Tính t?ng các ph?n t? c?a ma tr?n
  11. 4.      Tìm giá tr? nh? nh?t trên hàng 0 c?a ma tr?n.
  12. 5.       Ghi vào t?p matran1.txt nh?ng ph?n t? chia h?t cho 3 trong ma tr?n. Ð?c d? li?u t? t?p ra màn hình.
  13. */
  14.     int m, n;
  15.     printf("Nhap m, n  = ");
  16.     scanf("%d %d", &m, &n);
  17.     int a[m][n];
  18.     int tong = 0;
  19.     int i, j;
  20.     for (i = 0; i < m; i++)
  21.         for (j = 0; j < n; j++) {
  22.             printf("a[%d,%d] = ", i, j);
  23.             scanf("%d", &a[i][j]);
  24.             tong += a[i][j];           
  25.         }
  26.     printf("Tong cac phan tu cua ma tran la: %d\n", tong);
  27.     int max = a[0][0];
  28.     for (j = 1; j < n; j++)
  29.         if (a[0][j] > max ) max = a[0][j];     
  30.     printf("Gia tri lon nhat tren hang 0 cua ma tran la: %d\n", max);
  31.     FILE *fin, *fout;
  32.     fout = freopen("matran1.txt", "w", stdout);
  33.     for (i = 0; i < m; i++)
  34.         for (j = 0; j < n; j++)
  35.             if (a[i][j] % 3 == 0)
  36.                 printf("%d ", a[i][j]);
  37.     fclose(fout);
  38.  
  39.     return 0;
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement