C Programming Assignment 4 Write a recursive function named

C++ Programming Assignment 4

Write a recursive function named hex that takes a non-negative int parameter and prints the number in hexadecimal.

Using:

AND USING

Solution

#include <iostream>

using namespace std;
void hex(int n)
{
static char *s = \"0123456789ABCDEF\";
if (n >= 16)
{
hex(n/16);
cout << s[n%16];
}
else
{
cout << s[n];
}
}
int main()
{
cout<<\"\ For Decimal 122 -->\";
hex(122);

cout<<\"\ For Decimal 14 -->\";
hex(14);


return 0;
}

OUTPUT:

For Decimal 122 -->7A
For Decimal 14 -->E

C++ Programming Assignment 4 Write a recursive function named hex that takes a non-negative int parameter and prints the number in hexadecimal. Using: AND USING

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site