-
Notifications
You must be signed in to change notification settings - Fork 0
/
Warshall.cpp
73 lines (63 loc) · 1.38 KB
/
Warshall.cpp
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
#include<iostream>
// For windows users
#ifdef WIN32
#include<conio.h>
#endif
using namespace std;
#define SIZE 4 // Array size
void printArray(int arr[SIZE][SIZE]);
int main(void)
{
int input;
int arr[SIZE][SIZE];
for (int x = 0; x < SIZE; x++)
{
for (int y = 0; y < SIZE; y++)
{
cout << "Enter 0 and 1 : ";
cin >> input; // Get matrix parameters
arr[x][y] = input;
}
}
for (int x = 0; x < SIZE; x++)
{
for (int y = 0; y < SIZE; y++)
{
cout << arr[x][y] << " ";
}
cout << endl;
}
for (int t = 0; t < SIZE; t++)
{
for (int y = 0; y < SIZE; y++)
{
for (int x = 0; x < SIZE; x++)
{
if (arr[x][t] == 1)
{
if (arr[t][y] == 1)
arr[x][y] = 1;
}
}
}
}
printArray(arr); // Print warshall
// _getch() for Windows and cin.get() for others
#ifdef WIN32
_getch();
#else
cin.get();
cin.get();
#endif
}
// Print array function
void printArray(int arr[SIZE][SIZE])
{
cout << "The matrix is below the warshall :" << endl;
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < SIZE; j++)
cout << arr[i][j] << " ";
cout << endl;
}
}