Advertisement
sellmmaahh

popravni-sept-2014-zad3-GornjaTrougaona

Jul 30th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdexcept>
  3. #include <vector>
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9. bool GornjaTrougaona (vector<vector<double>> mat)
  10. {
  11. for (int i=0; i<mat.size(); i++) {
  12. if (mat[i].size()!=mat[0].size())
  13. throw domain_error ("Parametar nema formu matrice.");
  14. }
  15. for (int i=0; i<mat.size(); i++) {
  16. for (int j=0; j<mat[i].size(); j++)
  17. {
  18. if (i>j && mat[i][j]==0) return true;
  19. }}
  20. return false;
  21. }
  22.  
  23. int main () {
  24. cout<<"Unesite dimenzije matrice :";
  25. int br_red, br_kol;
  26. cin>>br_red>>br_kol;
  27. try {
  28. vector<vector<double>> mat(br_red,vector<double>(br_kol));
  29. cout<<"Unesite elemente matrice: "<<endl;
  30. for (int i=0; i<br_red; i++)
  31. for (int j=0; j<br_kol; j++)
  32. cin>>mat[i][j];
  33.  
  34. if (GornjaTrougaona(mat)) cout<<"Matrica je gornja trougaona.";
  35. else cout<<"Matrica nije gornja trougaona.";
  36. }
  37. catch(const char poruka[]) {
  38. cout<<poruka;
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement