阅读背景:

collatz猜想使用类打印对象的数量和序列

来源:互联网 
    #include<iostream>
    using namespace std;
    class ulam
    {
        int num;
        double prod;
        int cot;
    public:
        ulam(){cot=0;}
        ulam(int x)
        {
            num=x;
        }

        void process()
        {
          for(int i=0;num==1;i++)
          {
            cout<<num<<endl;
            if((num%2) == 0)
            {
              prod=num/2;
            }
            else
            {
              prod=(3*num)+1;
            }
            num=prod;
            cot++;
          }
        }
        void display()
        {
            cout<<"the number of steps required is: "<<cot;
        }
    };
    int main()
    {
        int n;
        cout<<"enter the number"<<endl;
        cin>>n;
        ulam obj(n);
        obj.process();
        obj.display();
    }
    #include<iostream>
    using namespace std;



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: