Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void main(void) {
- int i, j, l, k, a;
- int M[6][6];
- for (i = 0; i < 6; i++) {
- for (j = 0; j < 6; j++) {
- printf("Enter element with index [%d|%d]: ", i + 1, j + 1, "\n");
- scanf_s("%d", &a);
- if (a == 1 || a == 0) {
- printf("Error: Matrix can`t contain 1 and 0\n");
- return 0;
- }
- M[i][j] = a;
- }
- }
- printf("Your matrix\n");
- for (i = 0; i < 6; i++) {
- for (j = 0; j < 6; j++) {
- printf(" %d", M[i][j]);
- }
- printf("\n");
- }
- int num = M[0][0];
- for (i = 0; i < 6; i++) {
- for (j = 0; j < 6; j++) {
- num = M[i][j];
- l = j + 1;
- if ((M[i][j] != 1)) {
- M[i][j] = 0;
- }
- for (k = i; k < 6; k++) {
- while (l < 6) {
- if (num == M[k][l]) {
- M[i][j] = 1;
- M[k][l] = 1;
- }
- l++;
- }
- l = 0;
- }
- }
- }
- printf("New matrix\n");
- for (i = 0; i < 6; i++) {
- for (j = 0; j < 6; j++) {
- printf(" %d", M[i][j]);
- }
- printf("\n");
- }
- int z_count;
- int o_count;
- for (i = 0; i < 6; i++) {
- z_count = 0;
- o_count = 0;
- for (j = 0; j < 6; j++) {
- if (M[i][j] == 1) {
- o_count++;
- }
- else if(M[i][j] == 0){
- z_count++;
- }
- }
- printf("In the string number %d, there are %d ones and %d zeros\n", i + 1, o_count, z_count);
- }
- for (i = 0; i < 6; i++) {
- z_count = 0;
- o_count = 0;
- for (j = 0; j < 6; j++) {
- if (M[j][i] == 1) {
- o_count++;
- }
- else if (M[j][i] == 0) {
- z_count++;
- }
- }
- printf("In the column number %d, there are %d ones and %d zeros\n", i + 1, o_count, z_count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement