The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Thursday, September 1, 2011

The 3n+1 Problem


#include<stdio.h>
#include<conio.h>

void _3nplus1(int n,int&pt)
{
 pt++;
 if(n != 1)
 {
  if(n % 2 == 0)
    _3nplus1(n/2,pt);
  else
    _3nplus1(3*n+1,pt);
 }
}

void main()
{
 clrscr();
 int i,j,k=0,l=0;
 scanf("%d %d",&i,&j);

 do
 {
  _3nplus1(i,k);
  i++;
  if(k > l)
   l = k;
  k = 0;
 }while(i<=j);
 printf("\n\n%d",l);
 getch();
}

No comments:

Post a Comment