Re: 3n+1 problem of acm



On Sun, 30 Apr 2006 17:04:15 UTC, "sathyashrayan"
<sathyashrayan@xxxxxxxxxxxxxxx> wrote:

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;
}

Why does you destroy the set you've made when the if is true? When you
remove the whole if block there would be noch change on the result in
any case.

Hint: for what does else exist?

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?





--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
.



Relevant Pages

  • Re: Deadlocks on Update
    ... hint if you are not updating the table. ... WITHhint. ... > avalId int 4 No ... CleanCnt:1 Mode: U Flags: 0x0 ...
    (microsoft.public.sqlserver.programming)
  • Re: New to c++.net (need help)
    ... > using namespace std; ... > int main ... Here's a hint for when ... your program is behaving other than how you expect, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Bit fiddling
    ... int n; should be unsigned int n;, or a better solution would have ... Hint #2: Is the value of ~3 even or odd? ... divisibility-by-three test would make a useful improvement. ... On the six-year-old machine sitting in front of me at the ...
    (comp.lang.c)
  • Re: Reading some pieces of a file
    ... ron wrote: ... find how to open and read a file (hint: ... read the answer and compare ... int main ...
    (alt.comp.lang.learn.c-cpp)
  • Re: convert decimal number in a hexadecimal number ?
    ... I just gave him a hint of solution.... ... My fuction char* itoa(int val, int base) is perfectly right ..it ... Are you sure 31 characters is enough for a 256-bit int on DS9K? ...
    (comp.lang.c)