L(D)

#include "stdafx.h" #include <stdio.h> #include <stdbool.h> #include <conio.h> void main() { int a[10][10], i, j, k, n, t, vid[10]; bool f = false; //заполним массив "бесконечностями" for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { if (i != j) a[i][j] = 10000; else a[i][j] = 0; } } printf("\n enter the number of terms: \n"); scanf("%d", &n); //количество вершин printf("\n enter 2 terms witch are connected: \n"); scanf("%d %d", &i, &j); //считываем, есть ли пути между вершинами i и j, пока не подадим i = -1 while (i != -1) { a[i - 1][j - 1] = 1; scanf("%d %d", &i, &j); } for (k = 0; k < n; k++) for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (i != j) for (t = 0; t < n; t++) if (a[i][j] > a[i][t] + a[t][j]) a[i][j] = a[i][t] + a[t][j]; printf("\n enter your starting term: \n"); scanf("%d", &k); printf(" enter the number of finishing terms: \n"); scanf("%d", &n); printf("enter your finishing terms: \n"); for (i = 0; i < n; i++) { scanf("%d", &t); if (a[k - 1][t - 1] != 10000) //если конечная вершина достижима из начальной f = true; } if (f == false) printf("L(D) is empty"); else printf("congratulations! L(D) isn't empty"); getch(); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.