I'm a beginner in language c. Two-dimensional array Walsall algorithm

Asked 2 years ago, Updated 2 years ago, 127 views

I'm working on a code that can run the Walsall algorithm, but I don't get the answer I want from where it went wrong. For example,

2

3

100

010

000

4

1000

0010

1111

0000

When you do it, the result value should come out, but it comes out differently from entering the array. Where did it go wrong? Help!

#include <stdio.h>
#include <stdlib.h>

#define MAX 10 // Pre-processing array size

int main(void)
{                                       
    int num, v;
    int array[MAX][MAX];

    printf("\t--------------------------------------------------------\n");
    printf("\t\tWarshall's Algorithm\n");
    printf("\t--------------------------------------------------------\n\n");

    printf ("total number of data");
    scanf("%d", &v); // Enter 'total number of test data' in the data file


    while (v > 0) { // array input/output loop as many as data

        printf ("matrix size");
        scanf("%d", &num); // Enter 'size of matrix' in data file

        for (int m = 0; m < num; m++) {
            printf ("Enter Matrix\n");

            for (int n = 0; n < num; n++) {
                scanf( "%d", &array[m][n]); // array[num][num]
            }                                   // received data in the for syntax by the size of the matrix
        }

        /* /* Warshall's Algorithm */
        for (int k = 0; k < num; k++) {
            for (int i = 0; i < num; i++) {
                for (int j = 0; j < num; j++) {
                    array[i][j] = array[i][j] || (array[i][k] && array[k][j]);
                }
            }       // Store the i->j distance as the distance between i->k + k+j, i.e. i->k->j. 
        }

        printf("%d\n", num); // size output of matrix at execution result output
        for (int m = 0; m < num; m++) {
            for (int n = 0; n < num; n++) {
                printf("%2d", array[m][n]); // output of execution result with Warshall's Algorithm
            }
            printf("\n");
        }
        v--; // Calculate the total number of remaining test data to run
    }

    return 0;
}

c 2d-array

2022-09-20 19:30

1 Answers

I did it, but I think it's working

When entering the value of the matrix with the keyboard, didn't you enter it without space with 100 instead of putting in space like 100


2022-09-20 19:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.