Tusohian

Adjacent Matrix (DFS) - 1 Count

Oct 19th, 2017
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int i,j,n,sum,m[26][26];
  9.     srand(time(NULL));
  10.     char a = 'A' ;
  11.  
  12.     cout<<"Enter the number of values: ";
  13.     cin>>n;
  14.  
  15.     for(i=0; i<n; i++)
  16.     {
  17.         for(j=0; j<n; j++)
  18.         {
  19.             m[i][j]=rand()%2;
  20.         }
  21.     }
  22.  
  23.     for(i=0; i<n; i++)
  24.     {
  25.         for(j=0; j<n; j++)
  26.         {
  27.             cout<<m[i][j]<<" ";
  28.         }
  29.         cout<<endl;
  30.     }
  31.  
  32.     sum=0;
  33.     for(i=0; i<n; i++)
  34.     {
  35.         for(j=0; j<n; j++)
  36.         {
  37.             if(m[i][j]==1)
  38.             {
  39.                 sum=sum+1;
  40.             }
  41.         }
  42.         cout<<endl<<a <<" = "<<sum;
  43.         sum=0;
  44.         a++;
  45.     }
  46.  
  47. }
Add Comment
Please, Sign In to add comment