Advertisement
Guest User

Untitled

a guest
May 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int mat[100][100], nc, nr, i, j, nmax, nmin, imax=0, imin=0, jmax=0, jmin=0;
  6. cout<<"Numero righe: ";
  7. cin>>nr;
  8. cout<<"Numero colonne: " ;
  9. cin>>nc;
  10. for(i=0; i<nr; i++)
  11. {
  12. cout<< "Carica gli elementi della "<<i+1<<"^ riga"<<endl;
  13. for(j=0; j<nc; j++)
  14. cin>>mat[i][j];
  15. }
  16. nmax=mat[0][0];
  17. nmin=mat[0][0];
  18. for(i=0; i<nr; i++)
  19. {
  20. for(j=0; j<nc; j++)
  21. {
  22. if(mat[i][j]>nmax)
  23. {
  24. nmax=mat[i][j];
  25. imax=i;
  26. jmax=j;
  27. }
  28. if(mat[i][j]<nmin)
  29. {
  30. nmin=mat[i][j];
  31. imin=i;
  32. jmin=j;
  33. }
  34. }
  35. }
  36. cout<<"l'elemento maggiore e' "<<nmax<<" e si trova nella "<<imax+1<<"^ riga e nella "<<jmax+1<<"^ colonna"<<endl;
  37. cout<<"L'elemento minore e' "<<nmin<<" e si trova nella "<<imin+1<<"^ riga e nella "<<jmin+1<<"^ colonna"<<endl;
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement