![]() |
| | #16 |
| Registered User Join Date: Mar 2003
Posts: 134
| here is my code anywho ..... waiting the 3rd contestCode: #include <iostream>
using namespace std;
int cycles(int i);
int main()
{
int i=0,j=0,current_cycles=0,max_cycles=0;
cout<<"Please enter 0 for both ranges to exit program\n\n";
while(true)
{
cout<<"Enter start and end range ( ex 1 10): ";
cin >>i>>j;
if(i ==0 && j == 0 )break; //break from loop.
while(i <=j )
{
current_cycles = cycles(i++);
if(current_cycles >= max_cycles)max_cycles = current_cycles;
}
cout<<"Maximum cycles within this range: "<<max_cycles<<"\n\n";
max_cycles=0;
}
return 0;
}
int cycles(int i)
{
if(i == 1)return 1; //if 1 return 1
if(i%2 == 0) return 1 + cycles(i/2); //do this if even
else return 1 + cycles((3*i)+1); //do this if odd
}
Last edited by noob2c; 09-02-2005 at 06:28 PM. |
| noob2c is offline | |
| | #17 |
| Information Crocodile Join Date: Dec 2004
Posts: 204
| Wow!! valis entry is really great. Makes me wanna study asm now . |
| loko is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Expression Evaluator Contest | Stack Overflow | Contests Board | 20 | 03-29-2005 10:34 AM |
| Obfuscated Code Contest | Stack Overflow | Contests Board | 51 | 01-21-2005 04:17 PM |
| WANTED: Contest Master | kermi3 | A Brief History of Cprogramming.com | 15 | 01-23-2003 10:15 PM |