andy6804tw
7/19/2016 - 4:31 PM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?a=7869 這題就只是當偶數除二奇數乘以二加一直到一跳出迴圈

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?a=7869

這題就只是當偶數除二奇數乘以二加一直到一跳出迴圈

#include<stdio.h>   
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		while(n!=1){
		printf("%d\n",n);
		if(n%2==0)
			n/=2;
		else
			n=n*3+1;
		}
		printf("%d\n",n);
	}
	/* 
    題目:[C_MM253-易] 3x+1數列產生
    作者:1010
    時間:西元 2016 年 7 月 */
}