Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- /*
- * ESERCIZIO
- * Data una matrice float dare un bool che indica l'esistenza di 3 elementi
- * nella stessa colonna che se sommati danno null
- *
- * By Trupia Ludovico
- *
- */
- int main()
- {
- srand ( time ( NULL ) );
- int numero = 20;
- float matrice[numero][numero] , somma = 0.0 ;
- cout << endl;
- for ( int i = 0 ; i < numero ; i++ )
- {
- cout << "\t" ;
- for ( int j = 0 ; j < numero ; j++ )
- {
- matrice[i][j] = (rand() % 10000 + 1)/1000.0;
- if ( rand()%2 % 2 )
- {
- matrice[i][j] = 0 - matrice[i][j];
- }
- cout.precision(2);
- if( matrice[i][j] <= 0 ) cout << " "; else cout << " ";
- cout << fixed << matrice[i][j];
- }
- cout << endl << endl;
- }
- for ( int r = 0 ; r < numero ; r++ )
- {
- for ( int i = 0 ; i < numero-3 ; i++ )
- {
- for ( int j = i+1 ; j < numero-2 ; j++ )
- {
- for ( int k = j+1 ; k < numero ; k++ )
- {
- somma = matrice[i][r] + matrice[j][r] + matrice[k][r];
- cout << " i["<<i<<"] j["<<j<<"] k["<<k<<"] r["<<r<<"]\t|| somma["<<somma<<"]\t|| "<< matrice[i][r] << " " << matrice[j][r] << " " << matrice[k][r] << endl << endl ;
- if ( somma == 0 )
- {
- cout << endl << " La Colonna " << r << " ha somma NULLA ! ";
- system ( "PAUSE" );
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement