Advertisement
neogz

REK - Najveći uneseni broj

Aug 20th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. /*
  2.         Napravite rekurzivnu funkciju koja će zahtjevati unos pozitivnih brojeva od korisnika sve
  3.         dok  korisnik  ne  unese  negativan  broj  ili  broj  0.  Povratna  vrijednost  iz  funkcije  
  4.         treba  da najveći uneseni broj.
  5. */
  6.  
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. int r(int big)
  11. {
  12.     int broj;
  13.     cout << "Unesi broj: ";
  14.     cin >> broj;
  15.  
  16.     if (broj <= 0) return big;
  17.     if (broj > big) big = broj;
  18.     return r(big);
  19.  
  20. }
  21.  
  22. int main(){
  23.  
  24.     int najveci = r(0);
  25.     cout << "Najveci uneseni broj = " << najveci << endl;
  26.  
  27.  
  28.     system("pause>null");
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement