Advertisement
Guest User

Untitled

a guest
May 27th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. setlocale(LC_ALL, "rus");
  8. int v, r, x, y;
  9. cout << "Введите количество вершин = ";
  10. cin >> v;
  11. cout << "Введите колличество рёбер = ";
  12. cin >> r;
  13. int C[5][5];
  14. int B[5][9];
  15. for (int i = 0; i<v; i++) {
  16. for (int j = 0; j<v; j++) {
  17. C[j][i] = 0;
  18. }
  19. }
  20. for (int i = 0; i<v; i++) {
  21. for (int j = 0; j<r; j++) {
  22. B[i][j] = 0;
  23. }
  24. }
  25. cout << endl;
  26. for (int i = 0; i<r; i++) {
  27. cout << "Введите откуда выходит ребро № " << i + 1 << " : ";
  28. cin >> x;
  29. cout << "Введите куда входит ребро № " << i + 1 << " : ";
  30. cin >> y;
  31. C[y - 1][x - 1] += 1;
  32. B[x - 1][i] = 1;
  33. B[y - 1][i] -= 1;
  34. }
  35. cout << "Матрица смежности имеет вид:" << endl;
  36. for (int i = 0; i<v; i++) {
  37. for (int j = 0; j<v; j++) {
  38. cout << C[j][i] << " ";
  39. }
  40. cout << endl;
  41. }
  42. cout << "Матрица инцидентности имеет вид:" << endl;
  43. for (int i = 0; i<v; i++) {
  44. for (int j = 0; j<r; j++) {
  45. cout << setw(4) << B[i][j] << " ";
  46. }
  47. cout << endl;
  48. }
  49. system("pause");
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement