Advertisement
Gilgamesh858

somma_3_El_Col_Null

Dec 17th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. /*
  8.  * ESERCIZIO
  9.  * Data una matrice float dare un bool che indica l'esistenza di 3 elementi
  10.  * nella stessa colonna che se sommati danno null
  11.  *
  12.  * By Trupia Ludovico
  13.  *
  14.  */
  15.  
  16. int main()
  17. {
  18.     srand ( time ( NULL ) );
  19.     int numero = 20;
  20.  
  21.     float matrice[numero][numero] , somma = 0.0 ;
  22.  
  23.     cout << endl;
  24.  
  25.     for ( int i = 0 ; i < numero ; i++ )
  26.     {
  27.         cout << "\t" ;
  28.  
  29.         for ( int j = 0 ; j < numero ; j++ )
  30.         {
  31.             matrice[i][j] = (rand() % 10000 + 1)/1000.0;
  32.  
  33.             if ( rand()%2 % 2 )
  34.             {
  35.                 matrice[i][j] = 0 - matrice[i][j];
  36.             }
  37.             cout.precision(2);
  38.             if( matrice[i][j] <= 0 ) cout << " "; else cout << "  ";
  39.             cout << fixed << matrice[i][j];
  40.         }
  41.         cout << endl << endl;
  42.     }
  43.  
  44.  
  45.     for ( int r = 0 ; r < numero ; r++ )
  46.     {
  47.         for ( int i = 0 ; i < numero-3 ; i++ )
  48.         {
  49.             for ( int j = i+1 ; j < numero-2 ; j++ )
  50.             {
  51.                 for ( int k = j+1 ; k < numero ; k++ )
  52.                 {
  53.                     somma = matrice[i][r] + matrice[j][r] + matrice[k][r];
  54.                     cout << " i["<<i<<"] j["<<j<<"] k["<<k<<"] r["<<r<<"]\t|| somma["<<somma<<"]\t|| "<< matrice[i][r] << " " << matrice[j][r] << " "  << matrice[k][r] << endl << endl ;
  55.                     if ( somma == 0 )
  56.                     {
  57.                         cout << endl << " La Colonna " << r << " ha somma NULLA ! ";
  58.                         system ( "PAUSE" );
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.     }
  64.  
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement