程序要求输入一个整数,将经过处理得到1的过程输出来。
5
5*3+1=16 16/2=8 8/2=4 4/2=2 2/2=1 End
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <stdio.h> int main() { int n; scanf("%d", &n); while(n != 1) { if(n%2 == 0) { printf("%d/2", n); n = n/2; } else { printf("%d*3+1", n); n = n*3 + 1; } printf("=%d ", n); } printf("End "); return 0; }