3n + 1 acm的问题 [英] 3n+1 problem of acm
问题描述
亲爱的小组,
以下给出的链接我想在C中实现。
http://online-judge.uva.es/p/v1/100.html >
我写的代码甚至没有达到给出问题的
附近。(我只是在学习)
#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_FAILURE); < br $>
}
i = at oi(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);
}
返回0;
}
一旦n得到偶数,就把它除以2
,最后n到达偶数并终止。
任何人都可以给我一些线索或暗示正确实施。
以上?
" sathyashrayan"写道:
下面给出的链接我想在C中实现。
http://online-judge.uva.es/p/v1/100.html >
我写的代码甚至没有达到问题的附近。(我只是在学习)
#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 odd(unsigned int number)
然后返回1表示奇数。像奇数/偶数这样的名字简直就是烦人的b $ b。这是什么?奇?甚至?
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_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(奇数) == 0&& evn == 1)
n = n / 2;
计数器++;
printf("%lu和%d \ n",n,counter) ;
}
返回0;
}
一旦n得到偶数,它就将它除以两个
,并在结束时到达偶数和终止。
任何人都可以给我一些线索或暗示正确的实施。
以上?
我不喜欢不知道这是否是你需要的才能让它发挥作用。做错了是
a学习过程的大部分内容所以有帮助不是,如果这样,非常有帮助。
"锇"写道:
下面给出的链接我想在C中实现。
http://online-judge.uva.es/p/v1/100.html
我写的代码甚至没有达到给出的问题。(我只是在学习)
#include< stdio.h>
#include< stdlib.h>
unsigned evn,odd;
void odd_evn(unsigned int number)
{
if(
{
evn = 1;
奇数= 0;
}
evn = 0;
odd = 1 ;
}
除了用完一段时间外,上面的功能什么都不做。将其改为:
int odd(unsigned int number)
然后返回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_FAILURE);
}
i = atoi(argc [1]);
j = atoi(argc [2]);
for(n = i; n< j; n ++)
{
odd_evn(n);
if(odd == 1&& evn == 0)
不要做腰带和吊带的事情。写(
if(odd(...))
n =(3 * n)+ 1;
if( odd == 0&& evn == 1)
n = n / 2;
counter ++;
printf("%lu and%d \ n",n,counter );
}
返回0;
}
一旦n得到偶数,它就把它除以两个
,最后n达到偶数并终止。
任何人都可以给我一些线索或提示以便正确实施。
以上?
我不知道如果这就是你需要的全部功能。做错了
是学习过程的一个重要部分,所以如果有这样的帮助就不是很有帮助。
那个帖子完全是胡说八道。我没看到全局变量。忽略
我所说的一切,除了关于一个坏名字的部分。
" sathyashrayan"写道:
以下给出的链接我想在C中实现。
http://online-judge.uva.es/p/v1/100.html
>我写的代码甚至没有达到问题的附近。(我只是在学习)
#include< stdio.h>
#include< stdlib .h>
unsigned evn,odd;
void odd_evn(unsigned int number)
{
if((number%2)== 0 )
{
evn = 1;
奇数= 0;
}
evn = 0;
奇数= 1;
}
int main(int argv,char * argc [])
{
unsigned long n;
unsigned int i,j;
int counter = 0;
if(argv == 0&& argv> = 3)
任何数字如何等于0且大于3? br />
< snip>
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?
"sathyashrayan" writes:
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;
}
The function above does nothing except use up some time. change it to:
int odd(unsigned int number)
and then return 1 to signify odd. A name such as odd/even is simply
annoying. Which is it? odd? Even?
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)
Don''t do this belt and suspenders thing. Write
if(odd( ...) )
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?
I don''t know if that is all you need to make it work. Doing things wrong is
a huge part of the learning process so being helpful is not, in case like
this, very helpful.
"osmium" writes:
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;
}
The function above does nothing except use up some time. change it to:
int odd(unsigned int number)
and then return 1 to signify odd. A name such as odd/even is simply
annoying. Which is it? odd? Even?
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)
Don''t do this belt and suspenders thing. Write
if(odd( ...) )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?
I don''t know if that is all you need to make it work. Doing things wrong
is a huge part of the learning process so being helpful is not, in case
like this, very helpful.
That post is utter nonsense. I didn''t see the global variables. Ignore
everything I said except the part about a bad name.
"sathyashrayan" wrote:
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)
How can any number be equal to 0 and greater than 3?
<snip>
这篇关于3n + 1 acm的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!