C Board  

Go Back   C Board > Community Boards > Contests Board

Reply
 
LinkBack Thread Tools Display Modes
Old 09-02-2005, 06:26 PM   #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.
noob2c is offline   Reply With Quote
Old 09-02-2005, 09:28 PM   #17
Information Crocodile
 
Join Date: Dec 2004
Posts: 204
Wow!! valis entry is really great. Makes me wanna study asm now .
loko is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 10:22 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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