Home > Back-end >  C language programming
C language programming

Time:10-13

Will want to excuse me which bosses: using recursive method to input an integer in C 531, print out the 5,3,1

CodePudding user response:

 # include & lt; Stdio. H> 

Void print_number (int n);

Int main (void)
{
Int num=531;

Print_number (num);

printf("\n");

return 0;
}

Void print_number (int n)
{
If (n==0)
return;

Print_number (n/10);
Printf (" % d ", n % 10);
}


For your reference ~

CodePudding user response:

That if the input from the keyboard arbitrary number, could you tell me how to change?

CodePudding user response:

The
reference 1/f, confident boy reply:
 # include & lt; Stdio. H> 

Void print_number (int n);

Int main (void)
{
Int num=531;

Print_number (num);

printf("\n");

return 0;
}

Void print_number (int n)
{
If (n==0)
return;

Print_number (n/10);
Printf (" % d ", n % 10);
}


For reference ~
if the input from the keyboard, use the scanf, how can I change

CodePudding user response:

Don't change the assignment to the input line

CodePudding user response:

Int num=531; Change
Int num=0;
The scanf (" % d ", & amp; Num);
It is ok to

CodePudding user response:

Thank you for your help. Problem solved
  • Related