New Contest #2 C/c++ Welcome

This is a discussion on New Contest #2 C/c++ Welcome within the Contests Board forums, part of the Community Boards category; cool stuff there itsme here is my code anywho ..... waiting the 3rd contest Code: #include <iostream> using namespace std; ...

  1. #16
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    cool stuff there itsme

    here is my code anywho ..... waiting the 3rd contest

    Code:
    #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.

  2. #17
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    Wow!! valis entry is really great. Makes me wanna study asm now .

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression Evaluator Contest
    By Stack Overflow in forum Contests Board
    Replies: 20
    Last Post: 03-29-2005, 09:34 AM
  2. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  3. WANTED: Contest Master
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-23-2003, 09:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21