codepad | about

 Link:

C, pasted on Nov 25:
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 ``` ```#include #include #include #define MAX 100 void NhapMaTran(int a[][MAX], int &n) { do { printf("\nNhap n: "); scanf("%d", &n); if(n <= 1 || n > MAX) { printf("\nSo phan tu khong hop le. Xin kiem tra lai !"); } }while(n <= 1 || n > MAX); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { printf("\nNhap vao a[%d][%d] = ", i, j); scanf("%d", &a[i][j]); } } } void XuatMaTran(int a[][MAX], int n) { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { printf("%4d",a[i][j]); } printf("\n\n"); } } int TinhTongCacPhanTuChanNamTrenBien(int a[][MAX], int n) { int S = 0; // Duyệt 2 cột biên for(int i = 0; i < n; i++) { if(a[0][i] % 2 == 0) { S += a[0][i]; } if(a[n - 1][i] % 2 == 0) { S += a[n - 1][i]; } } // Duyệt 2 dòng biên bỏ qua các phần tử thuộc 2 cột đã duyệt for(int i = 1; i < n - 1; i++) { if(a[i][0] % 2 == 0) { S += a[i][0]; } if(a[i][n - 1] % 2 == 0) { S += a[i][n - 1]; } } return S; } int main() { int a[MAX][MAX], n; NhapMaTran(a,n); XuatMaTran(a,n); int tong = TinhTongCacPhanTuChanNamTrenBien(a, n); printf("\nTong cac phan tu chan nam tren bien = %d", tong); getch(); return 0; } ```

Output:
 ```1 2 3 4 5 6 7 8 9 10 ``` ```Line 17: error: conio.h: No such file or directory Line 5: error: expected ';', ',' or ')' before '&' token In function 'XuatMaTran': Line 31: error: 'for' loop initial declaration used outside C99 mode Line 33: error: 'for' loop initial declaration used outside C99 mode In function 'TinhTongCacPhanTuChanNamTrenBien': Line 45: error: 'for' loop initial declaration used outside C99 mode Line 57: error: redefinition of 'i' Line 45: error: previous definition of 'i' was here Line 57: error: 'for' loop initial declaration used outside C99 mode ```

Comments: