096.角谷猜想

举报
C语言与CPP编程 发表于 2022/05/03 22:27:56 2022/05/03
【摘要】 #include<stdio.h>void main(){ int n=1,count=0; clrscr(); puts("*********************************************************"); puts("* >> This ...

  
  1. #include<stdio.h>
  2. void main()
  3. {
  4. int n=1,count=0;
  5. clrscr();
  6. puts("*********************************************************");
  7. puts("* >> This program is to verify Jiaogu Guess << *");
  8. puts("* That is given any natural number, if it is an even, *");
  9. puts("* divides 2, if it is an odd, multiple 3 and add 1, the *");
  10. puts("* result continues to be calculated analogously. After *");
  11. puts("* some times, the result is always 1. *");
  12. puts("*********************************************************");
  13. while(n!=0)
  14. {
  15. printf(" >> Please input a number to verify(0 to quit): ");
  16. scanf("%d",&n); /*输入任一整数*/
  17. if(n==0)
  18. break;
  19. printf(" >> ------ Results of verification: ------------\n");
  20. do{
  21. if(n%2)
  22. {
  23. n=n*3+1; /*若为奇数,n乘3加1*/
  24. printf(" >> Step No.%d: %d*3+1=%d\n",++count,(n-1)/3,n);
  25. }
  26. else
  27. {
  28. n/=2; /*若为偶数n除以2*/
  29. printf(" >> Step No.%d: %d/2=%d\n",++count,2*n,n);
  30. }
  31. }while(n!=1); /*n不等于1则继续以上过程*/
  32. printf(" >> ---------------------------------------------\n");
  33. }
  34. puts("\n Press any key to quit...");
  35. getch();
  36. }

文章来源: blog.csdn.net,作者:程序员编程指南,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/weixin_41055260/article/details/124558308

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。