fork download
  1. #include <stdio.h>
  2.  
  3. int main(){
  4. int a[20][20];
  5. int m, n;
  6. printf("nhap m hang: ");
  7. scanf("%d", &m);
  8. printf("nhap n cot: ");
  9. scanf("%d", &n);
  10. for(int i = 0; i < m; ++i){
  11. for(int j = 0; j < n; ++j){
  12. printf("a[%d][%d] = ", i, j);
  13. scanf("%d", &a[i][j]);
  14. }
  15. }
  16. printf("\nMa tran vua nhap:\n");
  17. for(int i = 0; i < m; ++i){
  18. for(int j = 0; j < n; ++j){
  19. printf("%d ", a[i][j]);
  20. }
  21. printf("\n");
  22. }
  23. int x;
  24. int dem =0;
  25. printf ("nhap x:");
  26. scanf ("%d",&x);
  27. for (int i=1;i<=m;i++){
  28. for (int j=1;j<=n;j++){
  29. if (x==a[i][j]){
  30. printf("thay %d o vi hang %d,cot %d\n",x,i+1,j+1);
  31. dem++;
  32. }
  33. }
  34. }
  35. if (dem==0){
  36. printf ("Khong tim thay %d trong ma tran\n",x );
  37. }
  38. if (m == n) {
  39. int tongCheoChinh = 0;
  40. int tongCheoPhu = 0;
  41. printf("\nCac ptu cua duong cheo chinh: ");
  42. for (int i = 0; i < m; i++) {
  43. printf("%d ", a[i][i]);
  44. tongCheoChinh += a[i][i];
  45. }
  46. printf("\nTong duong cheo chinh = %d\n", tongCheoChinh);
  47. printf("Cac phan tu tren duong cheo phu la: ");
  48. for (int i = 0; i < n; i++) {
  49. printf("%d ", a[i][n - 1 - i]);
  50. tongCheoPhu += a[i][n - 1 - i];
  51. }
  52. printf("\nTong duong cheo ph? = %d\n", tongCheoPhu);
  53. } else {
  54. printf("\nMa tran ko ton tai,ko co duong cheo chinh,duong cheo phu.\n");
  55. }
  56. return 0;
  57. }
Success #stdin #stdout 0s 5356KB
stdin
Standard input is empty
stdout
nhap m hang: nhap n cot: 
Ma tran vua nhap:
















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































nhap x:Khong tim thay 0 trong ma tran

Ma tran ko ton tai,ko co duong cheo chinh,duong cheo phu.