http://acm.hdu.edu.cn/showproblem.php?pid=1279
角谷猜想就是很多oj上面都有提到的3n+1的问题,uhunt上面的100;
这题基本思路跟那题是一样的,就是在按格式输出上面有些不一样,第一奇数输出用printf(“%d”,a);
接下来的就用printf(“ %d”,a);,可以保证最后一个没有空格
View Code
#include<stdio.h> int main() { int n,a,i,flag,t=0; scanf("%d",&n); while(n--) { flag=0; scanf("%d",&a); while(a!=1) { if(a%2==1) { if(flag==0) printf("%d",a); else printf(" %d",a); a=a*3+1; flag=1; } else { a/=2; } } if(flag==0) printf("No number can be output !"); printf("\n"); } return 0; }