ٍِِDear Mr/Mis Ognjen
thanks for your answer....
but i wrote the program to what you said and i had some problems because when i run my program my output is not look like the output of problem but in my opinion it work correctly.
because between 1 to 10 we have 9 number that we can caculate .
2 ----> 1
3-----> 10 5 16 8 4 2 1
4-----> 2 1
5-----> 16 8 4 2 1
6----->3 10 5 16 8 4 2 1
7----->22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
8----->4 2 1
9-----> 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
i wrote this program, it can show the program you said but it output is not like the question output.
my program:
#include<iostream>
using namespace std;
int main(){
int i,j,n;
cin>>i>>j;
int temp;
int tool,max;
tool=j-i;
int array[tool];
for(int s=0;i<=j;i++,s++)
{
int counter=1;
int temp=i;
// cout<<temp<<" "; only for testing
while(temp>1)
{
if(temp%2==0)
temp=temp/2;
else
temp=temp*3+1;
counter++;
//cout<<" "<<temp; only for testing
}
//cout <<endl; only for testing
array[s]=counter;
}
max=array[0];
for(int j=0;j<tool;j++)
{
if(array[j+1]>array[j])
{
max=array[j+1];
}
}
cout<<" "<<i<< " "<<j<<" "<<max;
system("pause");
return 0;
}
Best Regards,
Bahador Saket