Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <iostream>
  4. using namespace std;
  5. int seque (int a);
  6. main()
  7. {
  8.     system("color B1");
  9.     int num=0;
  10.     cout<<"Inserisci un numero: ";
  11.     cin>>num;
  12.     num=seque (num);
  13.     system("pause");
  14.     return 0;
  15. }
  16. int seque(int a)
  17. {
  18.     int b;
  19.      if(a%2!=0)
  20.      {
  21.         a=a*3+1;
  22.         for( b=0;a==1;b++)
  23.         {          
  24.             a=a/2;
  25.             cout<<"  "<<a<<endl;
  26.             cout<<"Iterazione numero: "<<b;            
  27.         }
  28.      }
  29.      else
  30.      {
  31.         for( b=0;a==1;b++)
  32.         {
  33.             a=a/2;
  34.             cout<<"  "<<a<<endl;
  35.             cout<<"Iterazione numero: "<<b;
  36.         }
  37.      }
  38.      cout<<"Numero di iterazini: "<<b<<endl;
  39.     return b;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement