Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <iostream>
  2. //#include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int n, i, j, m, x, y, h, r=0, ok=0, a[10][10], v[40];
  7.  
  8.  
  9. int main()
  10. {
  11. cout<<"Dati nr de varfuri ";
  12. cin>>n;
  13. cout<<"Dati elementele matricei de adiacenta "<<endl;
  14.  
  15. for(i=1; i<n-1; i++)
  16. for(j=i+1; j<=n; j++)
  17. {
  18. cout<<"a["<<i<<"]["<<j<<"]=";
  19. cin>>a[i][j];
  20. a[j][i]=a[i][j];
  21. }
  22. m=0;
  23. for(i=1; i<=n; i++)
  24. for(j=1; j<=n; j++)
  25. if(a[i][j]==1)
  26. m++;
  27. m=m/2;
  28. if(m==n*(n-1)/2)
  29. cout<<"Graf complet";
  30. else
  31. cout<<"Graful nu este complet"<<endl;
  32.  
  33. for(i=1; i<=m; i++)
  34. {
  35. //cout<<"Introduceti x= "; cin>>x;
  36. //cout<<"Introduceti y= "; cin>>y;
  37.  
  38. a[x][y]=a[y][x]=1;
  39. }
  40. for(i=1; i<=n; i++)
  41. {
  42.  
  43. for(j=1; j<=n; j++)
  44. cout<<a[i][j]<<" "<<endl;
  45.  
  46. for(i=1; i<=n; i++)
  47. {
  48. h=0;
  49. for(j=1; j<=n; j++)
  50. if(a[i][j]==1)
  51. h++;
  52. r++;
  53. v[r]=h;
  54. }
  55. for(i=1; i<=n; i++)
  56. cout<<"nodul "<<i<<" are gradul "<<v[i]<<endl;
  57.  
  58. for(i=1; i<=n; i++)
  59. if(v[i]==0)
  60. ok=0;
  61. else
  62. ok=1;
  63. if(ok==0)
  64. cout<<"Graful are varfuri izolate"<<" ";
  65. else
  66. cout<<"Graful nu are varfuri izolate"<<" ";
  67.  
  68. return 0;
  69.  
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement