3n+1 problem of acm



Dear group,

The below given link which I want to implement in C.

http://online-judge.uva.es/p/v1/100.html

The code which I wrote does not even reaches the near to the
given problem.(I am just learning)

#include<stdio.h>
#include<stdlib.h>

unsigned evn,odd;

void odd_evn(unsigned int number)
{
if((number % 2) == 0)
{
evn = 1;
odd = 0;
}
evn = 0;
odd = 1;
}

int main(int argv, char *argc[])
{
unsigned long n;
unsigned int i,j;
int counter=0;
if(argv == 0 && argv >=3)
{
printf("eror\n");
exit(EXIT_FAILURE);
}

i=atoi(argc[1]);
j=atoi(argc[2]);
for(n=i; n<j;n++)
{
odd_evn(n);
if(odd == 1 && evn == 0)
n = (3 * n) + 1;
if(odd == 0 && evn == 1)
n = n / 2;
counter++;
printf("%lu and %d\n",n, counter);
}
return 0;
}

Once the n gets the even number it just divides it by two
and, at the end n reaches with even number and terminates.
Can any one give me some clue or hint for correct implementation.
of the above?



.



Relevant Pages

  • Re: Logical operator not working in if condition
    ... The "%d" specifier expects to store an `int', ... larger type) before shifting, and the result is of the same type. ... A much better way to test whether a number is even or odd is to do ... why logical operator not working in if condition. ...
    (comp.lang.c)
  • is it strings getline or just me?
    ... int main ... This is very odd to me since I have only entered one data input. ... was expecting that the program was awaiting a second set of indata but no ...
    (comp.lang.cpp)
  • Re: LAHF does not work ?
    ... >> int fun6{ ... Also, perhaps this is what was desired, but as noted above, the Parity Flag only ... > But this is using a sledgehammer to crack a nut -- ... That's the odd or even state of the overall integer, that is, the state of the ...
    (comp.lang.asm.x86)
  • Re: chicken and egg
    ... >>Odd. ... I have a whole directory full of smallish C programs, ... Compile. ... > int main{ ...
    (comp.os.linux.misc)
  • Re: 3n+1 problem of acm
    ... void odd_evn(unsigned int number) ... evn = 1; ... odd = 0; ... Can any one give me some clue or hint for correct implementation. ...
    (comp.lang.c)