Guest User

Untitled

a guest
Dec 11th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. //Given an incidence matrix of an undirected graph, list its
  2. //edges and give the number of times each edge appears.
  3. #include <iostream>
  4. #define max 100
  5.  
  6. using namespace std;
  7. void input(int &n, int &edge, int a[][max])
  8. {
  9. cout<<"Input the number of vertices of the graph n= ";
  10. cin>>n;
  11. cout<<"Input the number of edges of the graph = ";
  12. cin>>edge;
  13. for(int i=1;i<=n;i++)
  14. for(int j=1;j<=edge;j++)
  15. {
  16. cout<<"a["<<i<<"]["<<j<<"] = ";
  17. cin>>a[i][j];
  18. }
  19. }
  20. void done(int n, int edge, int a[][max])
  21. { int b1,b2;
  22. for(int i=1;i<=edge;i++)
  23. {
  24. for(int j=1;j<=n;)
  25. {
  26. if(a[j][i]!=0)
  27. {
  28. b1=j;
  29. for(int k=j+1;k<=n;k++)
  30. if(a[k][i]!=0)
  31. {
  32. b2=k;
  33. cout<<"There is "<<a[b1][i]<<" egdes between "<<b1<<" and "<<b2<<endl;
  34.  
  35. }
  36. j++;
  37. }
  38. else j++;
  39. }
  40. }
  41.  
  42. }
  43. main()
  44. {
  45. int n, edge, a[max][max];
  46. input(n,edge,a);
  47. done(n,edge,a);
  48. system("pause");
  49. }
Add Comment
Please, Sign In to add comment