// Define the recursive function.
int collatz(int p1)
{
// While Loop Starting
while (p1>1)
{
//when the number is even
if(p1%2==0)
{
p1 = p1/2;
printf("%d ", p1);
//using recursion
return collatz(p1);
}
// Case where number is odd.
elseif
{
p1 = 3*p1+1;
//print function
printf("%d ", p1);
//using recursion
return collatz(p1);
}
}
}
// Main body.
int main()
{
// Declare the variable and initialized it.
int p1= 4;
//print function
printf("User Entered value : %d\n", p1);
// Display the number
printf("%d\n", collatz(p1));
//End
return 0;
}
出力を繰り返しました。必要な作業をしてください。このCollatzシーケンスは
1)CとC++は異なる言語です。一つを選ぶ! 2)これはCでもC++でもありません。 3)[ask]を参照してください。 – Olaf
私はCで書いた – chandu
なぜ別の言語のタグを追加したのですか?他の2つの問題を尊重して質問を編集してください。 – Olaf