edutedu

obtinerea inversului unui numar (recursiv)

Jan 15th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. long long numar(int n)
  5. {
  6. int cif;
  7. cout<<"cifra"; cin>>cif;
  8. if(cif<0 || cif>9)
  9. return n;
  10. else
  11. return numar(n*10+cif);
  12. }
  13. int main()
  14. {
  15. int nr;
  16. nr=numar(0);
  17. cout<<"numarul= "<<nr;
  18. return 0;
  19. }
Add Comment
Please, Sign In to add comment