Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <malloc.h>
- void roy_w(int **a, int n, int m[10][10]) {
- int i, j, k, gasit = 0;
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- m[i][j] = a[i][j];
- for (j = 0; j < n; j++)
- for (i = 0; i < n; i++)
- if (m[i][j]==0)
- for (k = 0; k < n; k++)
- if (m[i][k] && m[k][j]) m[i][j] = 1;
- }
- int **alocare(int m, int n) {
- int **mat, i;
- mat = (int **)malloc(m*sizeof(int *));
- for (i = 0; i < m; i++)
- *(mat + i) = (int *)malloc(n*sizeof(int));
- return mat;
- }
- void dezaloca(int **mat, int m) {
- int i;
- for (i = 0; i < m; i++)
- free(*(mat + i));
- free(mat);
- }
- void main() {
- int n, v0, **a, m, i, j, vf1, vf2, mat[10][10];
- printf_s("Nr. varfuri: "); scanf_s("%i", &n);
- a = alocare(n, n);
- for (i = 0; i < n; i++)
- for (j = 0; j <= i; j++)
- a[i][j] = a[j][i] = 0;
- printf_s("\nNr. muchii: "); scanf_s("%i", &m);
- for (i = 0; i < m; i++) {
- printf_s("Varf initial: "); scanf_s("%i", &vf1);
- printf_s("Varf final: "); scanf_s("%i", &vf2);
- a[vf1 - 1][vf2 - 1] = a[vf2 - 1][vf1 - 1] = 1;
- }
- roy_w(a, n, mat);
- dezaloca(a, n);
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement