C Write Unicode Exponents to Terminal

Kibicho Murage
Mar 11, 2021

TO DO:

  • Insert rant about Github’s lazy F.E engineers*. Please add the option to change fonts.
  • Figure out if array elements should be null terminated
  • Make function recursive: I think it will be cleaner
/*
* Array of unicode exponents (0 - 9)
*/
static char superscriptArray[10][6] =
{
"\u2070\0","\u00B9\0","\u00B2\0","\u00B3\0","\u2074\0",
"\u2075\0","\u2076\0","\u2077\0","\u2078\0","\u2079\0",
};
/*
Name: DecimalToExponent
Role: Prints decimal number as unicode exponent
Input: int number
Output: void
Sample: 123 -> ¹²³
*/
void DecimalToExponent(int number)
{
if(number == 0)
{
return;
}
int lastDigit = number % 10;
DecimalToExponent(number / 10);
printf("%s", superscriptArray[lastDigit]);
}
int main()
{
DecimalToExponent(123);
return 0;
}

--

--

Kibicho Murage
0 Followers

AI Researcher at Fileforma. Twitter : murage_kibicho