Advertisement
Five_NT

[C++]Formare matrice de incidenta din adiacenta

Jan 23rd, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int a[10][10], n, m, b[100][100];
  7.  
  8. void citire();
  9.  
  10. int main()
  11. {
  12.     citire();
  13.     for(int i=1; i<=n; i++)
  14.     {
  15.         for(int j=1; j<=m; j++)
  16.             cout<<b[i][j]<<"    ";
  17.         cout<<'\n';
  18.     }
  19.     return 0;
  20. }
  21.  
  22. void citire()
  23. {
  24.     ifstream f("c.in");
  25.     f>>n;
  26.     for(int i=1; i<=n; i++)
  27.         for(int j=1; j<=n; j++)
  28.         {
  29.             f>>a[i][j];
  30.             if(a[i][j] == 1)
  31.             {
  32.                 m++;
  33.                 b[i][m] = 1;
  34.                 b[j][m] = -1;
  35.             }
  36.         }
  37.     f.close();
  38. }
  39. /* c.in */
  40. 6
  41. 0 1 1 0 0 0
  42. 0 0 1 0 0 1
  43. 0 0 0 0 0 0
  44. 0 0 1 0 1 0
  45. 0 0 0 0 0 0
  46. 1 0 0 1 1 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement