Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- void readN(int &m);
- int WriteSequence(int m);
- int CountToArray(int A[],int m);
- void WriteArray(int A[],int e1);
- int main()
- {
- int n;
- readN(n);
- int cnt=0;
- cnt=WriteSequence(n);
- cout<<" -> "<<" in the sequence we have "<<cnt<<" numbers."<<endl;
- int X[100];
- cnt=CountToArray(X,n);
- WriteArray(X,cnt);
- return 0;
- }
- void readN(int &m)
- {
- cin>>m;
- }
- bool even(int what)
- {
- return ((what%2)==0);
- }
- int WriteSequence(int m)
- {
- int j=0, i=m;
- cout<<"Sequence: ";
- while(i>1)
- {
- if(even(i))
- {i=i/2;}
- else {i=i*3+1;}
- j++;
- cout<<"->"<<i;
- }
- return j;
- }
- int CountToArray(int A[],int m)
- {
- int j=0, i=m;
- cout<<"Sequence: ";
- while((i>1)&&(j<100))
- {
- if(even(i))
- {
- i=i/2;
- }
- else {i=i*3+1;}
- A[j]=i;
- j++;
- }
- return j;
- }
- void WriteArray(int A[],int e1)
- {
- cout<<"array: ";
- for(int i=0;i<e1;i++)
- {
- cout<< " -> "<<A[i];
- }
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement