The problem is here The 3n + 1 problem

My solving code is

   #include<stdio.h>
   int sifi(int i);

int main()
{
   int n,m;
   int i,j;
   int array[2];

  array[0]=0;

scanf("%d %d",&m,&n);

for(i=n;i>=m;i--)
{
    array[1] = sifi(i);


    if(array[1]>array[0])
    {
        array[0]=array[1];
    }

}

printf("%d %d %d",m,n,array[0]);
return 0;
 }



int sifi(int i)
{
int a,t=0;

for(a=i;a>1 ; )
{

    if(a%2==0)
    {
        a=a/2;
    }
    else
    {
        a=(3*a)+1;
    }
    t++;
}

  return t+1;
}

what is the wrong of my code. it show wrong answer.

asked 14 Dec '16, 15:46

rahul28's gravatar image

rahul28
7923

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×14
×1

question asked: 14 Dec '16, 15:46

question was seen: 844 times

last updated: 14 Dec '16, 15:46