Home > Back-end >  C language function, save the sprout new!!!! Output hexadecimal Numbers (recursive version)
C language function, save the sprout new!!!! Output hexadecimal Numbers (recursive version)

Time:09-27



Please write a recursive function, in the form of hexadecimal output natural number,

The function prototype

Void PrintHex (int num, int cap);

Note: output parameter num to stay natural number, cap for capital, function of natural number num in hexadecimal form output, expressed as A letter A ~ F or A ~ F for 10 ~ 15 Numbers, if the cap is 1 (true), is to use capital letters, otherwise use lowercase letters,

The referee program

#include
Void PrintHex (int num, int cap);
Int main ()
{int n, c; The scanf (" % d % d ", & amp; N, & amp; C);
PrintHex (n, c);
Putchar (" \ n ");
return 0;
}
/* * you submit the code will be embedded in here/

Test data

The input sample output sample
0 0 0
37 0 25
936 1 3 a8
2147483647 7 FFFFFFF

Requirements: shall not use loop statement, call printf function,

CodePudding user response:

Void PrintHex (int num, int cap)
{
C=int num % 16;
Int r=num/16;
If (r!=0) PrintHex (r, cap);
If (cap)
Printf (" % x ", c);
The else
Printf (" % X ", c);
};

CodePudding user response:

Oh, don't let use printf
Then put the sentence to replace putchar, just want to do the transformation of the
Void PrintHex (int num, int cap)
{
C=int num % 16;
Int r=num/16;
If (r!=0) PrintHex (r, cap);

If (c & lt; 10)
Putchar (c + '0');
The else
Putchar (cap? C + 'A' - 10: c + 'A' - 10);
};

CodePudding user response:

Love you, large to you many a semicolon
  • Related