Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int *distancias(int A[6][6], int c) {
- int *d, i, j, di;
- int fila[6], ini, fim;
- d = calloc(6, sizeof(int));
- for (j = 0; j < 6; j++) {
- d[j]=6;
- }
- d[c] = 0;
- ini = 0;
- fim = 0;
- fila[fim++] = c;
- while (ini != fim) {
- i = fila[ini++];
- di = d[i];
- for (j = 0; j < 6; j++) {
- if(A[i][j] == 1 && d[j] >= 6){
- d[j] = di + 1;
- fila[fim++] = j;
- }
- }
- }
- return d;
- }
- int main(int argc, char const *argv[]) {
- int c, i, j, A[6][6];
- int count = 6;
- int *fila;
- for (i = 0; i < count; i++) {
- for (j = 0; j < count; j++) {
- scanf("%d", &A[i][j]);
- }
- }
- scanf("%d", &c);
- printf("\n");
- printf("Matriz:\n");
- for (i = 0; i < count; i++) {
- for (j = 0; j < count; j++) {
- printf("[%d] ", A[i][j]);
- }
- printf("\n");
- }
- fila = distancias(A, c);
- printf("\n");
- printf("Fila:\n");
- for(i = 0; i < count; i++){
- printf("[%d] ", fila[i]);
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement