Advertisement
Shishu

Adjacent matrix

Oct 26th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 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,m[26][26];
  9.     srand(time(NULL));
  10.     char a = 'A' ;
  11.  
  12.  
  13.     cout<<"Enter the number of values: ";
  14.     cin>>n;
  15.  
  16.     for(i=0; i<n; i++)
  17.     {
  18.         for(j=0; j<n; j++)
  19.         {
  20.             m[i][j]=rand()%2;
  21.         }
  22.     }
  23.  
  24.     for(i=0; i<n; i++)
  25.     {
  26.         for(j=0; j<n; j++)
  27.         {
  28.             cout<<m[i][j]<<" ";
  29.         }
  30.         cout<<endl;
  31.     }
  32.  
  33.     for(i=0; i<n; i++)
  34.     {
  35.         cout<<endl<<a<<" = ";
  36.  
  37.         for(j=0; j<n; j++)
  38.         {
  39.             if(m[i][j]==1)
  40.             {
  41.                 cout<<(char)('A'+j)<<",";
  42.             }
  43.         }
  44.  
  45.  
  46.  
  47.         a++;
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement