Advertisement
HmHimu

adj matrix245

Jun 3rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int v,a,b,k=1;
  6. cout<<"number of vertex: ";
  7. cin>>v;
  8. int m[v][v];
  9. for(int i=0;i<=v;i++)
  10. {
  11. for(int j=0;j<=v;j++)
  12. {
  13. m[i][j]=0;
  14. }
  15. }
  16.  
  17. while(1)
  18. {
  19. cout<<"edge : "<<k<<endl;
  20. cin>>a>>b;
  21. if(a>v || b>v)
  22. {
  23. cout<<"please input valid input"<<endl;
  24. }
  25. else if(a==0 && b==0)
  26. {
  27. break;
  28. }
  29. else
  30. {
  31. m[a][b]=1;
  32. m[b][a]=1;
  33. k++;
  34. }
  35. }
  36. for(int i=1;i<=v;i++)
  37. {
  38. for(int j=1;j<=v;j++)
  39. {
  40. cout<<m[i][j]<<" ";
  41. }
  42. cout<<endl;
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement