Home > Back-end >  ] by [recursive method to replace an integer n with string. For example, enter 483, output string sh
] by [recursive method to replace an integer n with string. For example, enter 483, output string sh

Time:09-21

Key points: how to % 4 c output,
Presence of bosses can write this program
Thank you very much!

CodePudding user response:

More than 483/10=48 (3, 3 came out
More than 48/10=4, 8, 8 came out
More than 4/10=0, 4, 4 came out
An analogy

CodePudding user response:

///recursive method to replace an integer n with string, for example, enter 483, should be output string 4 August 3 (% 4 c output),
//note that n digits are not sure, can be any number of integers,
#include
Int zhuanhuan (int);
Int zhuanhuan (int n)
{
If (n<0)
{printf (" - ");
N=- n;
}
If (n>=0 & amp; & n<=9)
{printf (" % 4 d, n);//we use % 4 d is bad?
}
The else
{zhuanhuan (n/10);
Printf (" % 4 d ", n % 10);
}
return 0;
}
Int main ()
{
int n;
The scanf (" % d ", & amp; N);
Zhuanhuan (n);
return 0;
}

CodePudding user response:

refer to the second floor Tryagain2006 response:
///recursive method to replace an integer n with string, for example, enter 483, output string should be 4 August 3 (% 4 c output),
//note that n digits are not sure, can be any number of integers,
#include
Int zhuanhuan (int);
Int zhuanhuan (int n)
{
If (n<0)
{printf (" - ");
N=- n;
}
If (n>=0 & amp; & n<=9)
{printf (" % 4 d, n);//we use % 4 d is bad?
}
The else
{zhuanhuan (n/10);
Printf (" % 4 d ", n % 10);
}
return 0;
}
Int main ()
{
int n;
The scanf (" % d ", & amp; N);
Zhuanhuan (n);
return 0;
}

Thank you, know,

CodePudding user response:

 
//algorithm
Void trans (int num)
{
Trans (num % 10);
Printf (" % d, num/10);
}

Probably that's it,