Re: 3n+1 problem of acm
- From: "Herbert Rosenau" <os2guy@xxxxxxxxxxxxx>
- Date: Sun, 30 Apr 2006 19:16:33 +0000 (UTC)
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!
.
- References:
- 3n+1 problem of acm
- From: sathyashrayan
- 3n+1 problem of acm
- Prev by Date: Re: Boost process and C
- Next by Date: Re: help me learn C
- Previous by thread: Re: 3n+1 problem of acm
- Index(es):
Relevant Pages
|