Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4. int nx,VA;
  5. cout<<"Este programa imprimira una secuencia de numeros iterativamente "<<endl;
  6.  
  7. cout<<"Ingresar numero"<<endl;
  8. cin>>nx;
  9.  
  10.  
  11. if(nx<=0){
  12. cout<<"Chupa el pico ctm, pone otro numero: ";
  13. cin>>nx;
  14. }
  15.  
  16.  
  17. while(nx>0){
  18.  
  19. cout<<nx<<" / ";
  20.  
  21. if(nx%2==0){
  22.  
  23. nx=nx/2;
  24. cout<<nx<<" / ";
  25.  
  26. }
  27. else if(nx==1){
  28. break;
  29. }
  30.  
  31. else if(nx%2==1){
  32. nx=(3*nx)+1;
  33. cout<<nx<<" / ";
  34.  
  35. }
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement