Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int N=5;
- bool diagonale (int A[][N]);
- int main()
- {
- int A[][N]={{0,1,2,3,4},
- {5,6,7,8,9},
- {0,1,2,3,4},
- {5,6,7,8,9},
- {0,1,-6,3,4}};
- int i=0,k;
- while (i<N)
- {
- k=0;
- while (k<N)
- {
- cout<<A[i][k]<<" ";
- k++;
- }
- cout<<endl;
- i++;
- }
- cout<<"Sto cercando l'elemento opposto nella diagonale destra inferiore: per esempio 8 e -8 oppure 4 e -4\n";
- cout<<"se lo trovo allora stampo true!.... ed ecco a voi ..."<<diagonale(A);
- return 0;
- }
- bool diagonale (int A[][N])
- {
- int a,i,b=1,k=0,j,l;
- i=b;
- while (b<(N-1))
- {
- a=A[i][k];
- j=i+1;
- l=k+1;
- while (j<N)
- {//cout<<A[j][l]<<"\n"; // per debug
- if (a==(-(A[j][l]))) return true;
- j++;
- l++;
- }
- k++;
- i++;
- if (i==N-1)
- {
- b++;
- i=b;
- k=0;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement