Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int nrmaxim(int n)
  7. {
  8. int aux=n;
  9. int nrcif=0;
  10. while(aux!=0)
  11. {
  12. nrcif++;
  13. aux=aux/10;
  14.  
  15. }
  16. int p=1;
  17. for(int i=1;i<=nrcif;i++)
  18. p=p*10;
  19. long long numarnou=n*p+n;
  20. int max=n;
  21. int numar=0;
  22. for(int i=1; i<=nrcif;i++)
  23. {
  24. numar=numarnou%p;
  25. if(numar>max)
  26. max=numar;
  27. numarnou=numarnou/10;
  28.  
  29. }
  30.  
  31.  
  32.  
  33. return max;
  34.  
  35.  
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. int main()
  52. {
  53. cout<<nrmaxim(123456789);
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement