Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, e;
  8. cout << "How many nodes?: " << endl;
  9. cin >> n;
  10. int a[n][n];
  11. memset(a, 0, (sizeof(a)*2));
  12.  
  13. for(int i=1; i<=n; i++)
  14. {
  15. cout << "How many edges is node "<< i << " connecting to?: " << endl;
  16. cin >> e;
  17. cout << "Enter " << e << " nodes" << endl;
  18. for(int j=1; j<=e; j++)
  19. {
  20. int x;
  21. cin >> x;
  22. a[i][x] = 1;
  23. }
  24. }
  25.  
  26. for(int i=1; i<=n; i++)
  27. {
  28. for(int j=1; j<=n; j++)
  29. {
  30. cout << a[i][j] << " ";
  31. }
  32. cout << endl;
  33. }
  34.  
  35. for(int i=1;i<=n;i++)
  36. {
  37. int out = 0;
  38. for(int j=1;j<=n;j++)
  39. {
  40. if(a[i][j]==1)
  41. out++;
  42. }
  43. cout << "Outdegree of " << i << " is " << out;
  44. cout << endl;
  45. }
  46. cout << endl;
  47. for(int i=1;i<=n;i++)
  48. {
  49. int in = 0;
  50. for(int j=1;j<=n;j++)
  51. {
  52. if(a[j][i]==1)
  53. in++;
  54. }
  55. cout << "Indegree of " << i << " is " << in;
  56. cout << endl;
  57. }
  58. cout << endl;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement