30 Points

Reversed itoa

Darn! You left your stdlib at home! Without your essential C libaries, you need to write a function that, given an integer converts it to a string in reverse. Negative integers should be printed in reverse, but have a negative symbol prepended.

Start writing your function using this wrapper. Feel free to adapt it to your language of choice.

#include <stdlib.h>
#include <stdio.h>

char * myItoaReversed(int number) {
    return "Implement Me!";
}

int main() {
    int number;
    scanf("%d", &number);
    char * numberAsString = myItoaReversed(number);
    printf("%s\n", numberAsString);
}

Restrictions

  • sscanf or alike are not allowed
  • You are to implement the conversion. No library calls allowed

Example Input

1000

Example Output

0001

Example Input

-1872

Example Output

-2781