Advertisement
venik2405

lab1_2_2

Sep 9th, 2021
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <stdio.h>;
  2.  
  3. void main(void) {
  4. int i, j, l, k, a;
  5. int M[6][6];
  6. for (i = 0; i < 6; i++) {
  7. for (j = 0; j < 6; j++) {
  8. printf("Enter element with index [%d|%d]: ", i + 1, j + 1, "\n");
  9. scanf_s("%d", &a);
  10. if (a == 1 || a == 0) {
  11. printf("Error: Matrix can`t contain 1 and 0\n");
  12. return 0;
  13. }
  14. M[i][j] = a;
  15. }
  16. }
  17. printf("Your matrix\n");
  18. for (i = 0; i < 6; i++) {
  19. for (j = 0; j < 6; j++) {
  20. printf(" %d", M[i][j]);
  21. }
  22. printf("\n");
  23. }
  24. int num = M[0][0];
  25. for (i = 0; i < 6; i++) {
  26. for (j = 0; j < 6; j++) {
  27. num = M[i][j];
  28. l = j + 1;
  29. if ((M[i][j] != 1)) {
  30. M[i][j] = 0;
  31. }
  32. for (k = i; k < 6; k++) {
  33. while (l < 6) {
  34. if (num == M[k][l]) {
  35. M[i][j] = 1;
  36. M[k][l] = 1;
  37. }
  38. l++;
  39. }
  40. l = 0;
  41. }
  42. }
  43. }
  44. printf("New matrix\n");
  45. for (i = 0; i < 6; i++) {
  46. for (j = 0; j < 6; j++) {
  47. printf(" %d", M[i][j]);
  48. }
  49. printf("\n");
  50. }
  51. int z_count;
  52. int o_count;
  53. for (i = 0; i < 6; i++) {
  54. z_count = 0;
  55. o_count = 0;
  56. for (j = 0; j < 6; j++) {
  57. if (M[i][j] == 1) {
  58. o_count++;
  59. }
  60. else if(M[i][j] == 0){
  61. z_count++;
  62. }
  63. }
  64. printf("In the string number %d, there are %d ones and %d zeros\n", i + 1, o_count, z_count);
  65. }
  66. for (i = 0; i < 6; i++) {
  67. z_count = 0;
  68. o_count = 0;
  69. for (j = 0; j < 6; j++) {
  70. if (M[j][i] == 1) {
  71. o_count++;
  72. }
  73. else if (M[j][i] == 0) {
  74. z_count++;
  75. }
  76. }
  77. printf("In the column number %d, there are %d ones and %d zeros\n", i + 1, o_count, z_count);
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement