3n+1 problem of acm
- From: "sathyashrayan" <sathyashrayan@xxxxxxxxxxxxxxx>
- Date: Sun, 30 Apr 2006 22:34:15 +0530
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?
.
- Follow-Ups:
- Re: 3n+1 problem of acm
- From: Herbert Rosenau
- Re: 3n+1 problem of acm
- From: Michael Mair
- Re: 3n+1 problem of acm
- Prev by Date: Re: Question about "enums"
- Next by Date: Re: String Pattern Matching algo
- Previous by thread: Compute buffer size at compile-time
- Next by thread: Re: 3n+1 problem of acm
- Index(es):
Relevant Pages
|