这个程序不知道问题出在哪里,请各位路过的大佬帮帮萌新,谢谢:
#include<stdio.h>
int main()
{
int n = 0,count = 0,num[100] = {0};//一个用来输入,一个用来索引,一个用来初始化数组
scanf("%d",&n);
if(n == 1)//处理1的特殊情况
{
goto a;
}
while(n != 1)//对其进行一个奇偶性判断
{
a: if(n % 2==0)
{
n /= 2;
count++;
}else{
n = n*3 + 1;
count++;
}
num[count] = n;//给相应索引下的数组区赋值(说法可能有误)
}
for(int i = count;i>0;i--)//倒序获取数组的每个元素,打印到控制台
{
printf("%d ",num[i]);
}
return 0;
}