第三个点和第五个点通过不了,一红一黑,救救孩子吧(只学过c的小白)
查看原帖
第三个点和第五个点通过不了,一红一黑,救救孩子吧(只学过c的小白)
588175
LL3212701152楼主2021/12/14 22:44
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
	int n = 0,i=0,count = 0;
	scanf("%d", &n);
	int a[101];
	a[0] = n;
	int x = n;
	for (i = 1;; i++)
	{
		
		if (x % 2 != 0)
		{
			a[i] = x * 3 + 1;
			x = a[i];
		}
		else
		{
			a[i] =x / 2;
			x = a[i];
		}
		if (x == 1)
		{
			a[i] = x;
			break;
		}
		count++;
	}
	for (i = count+1; i >= 0; i--)
	{
		printf("%d ", a[i]);
	}
}

2021/12/14 22:44
加载中...