Can any one Please tell me what is wrong with this code
it keeps giveing me wrong answer "zero"
//////////////////////////////////////...
#include "stdio.h"
int proc(int x)
{
int counter=0;
while(x!=1)
{
if(x%2==0)
{
x=x/2;
}
else if(x%2!=0)
{
x=(3*x)+1;
}
counter++;
}
return counter;
}
int main()
{
int i;
int j;
int c=0;
int num;
int max=0;
FILE *in=fopen("pro.in","r");
FILE *out=fopen("pro.out","w");
fscanf(in,"%d",%26amp;i);
fscanf(in,"%d",%26amp;j);
for(num=i;num%26lt;=j;num++)
{
c=proc(num);
if(max%26lt;c)
{
max==c;
}
}
fprintf(out,"%d",max);
return 0;
}
//////////////////////////////////////...
3n+1 Problem "c programming"?
first solution is don't use an int data type because it will not return a number with decimal places, instead use a float data type where it can return a number with decimal places. this is only a guess because i didn't get what you wanted as an output
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment