Write a function that takes an int and returns a chararray containing the string representation of the integer.
Rationale: Assume that the chararray has enough space to contain the int. Use the following function header:
void convert(int x, char * buf) {};
 Start with an empty string;
 Take every digit of the integer one by one, starting with the least significant one, and append it to the string;
 If the number was initially negative append a ‘‘ character to the string
 Reverse the string.
For example, given the input 318513513, we would add 3,1,5,3,1,5,8,1,3 and – in the string and then reverse it, producing the initial number.
Before solving this problem do the following (not limited to):
 Clarify doubts
 Write/loudly speak/analyze single or multiple pseudocode(e.g. trivial algorithm to advanced algorithm/Data Structures) which can lead to solution
 Explain any assumptions or limitations on the written pseudocode
 Mention major data structures to be used
 Also how the positive/negative functional tests prove that the resultant solution is correct.
Clarification Points
Clarification Point1:
What is the maximum size of the number? If it’s more than 10, we may need to use the type long instead of integers.
Clarification Point2:
Can the number be negative? Does the sign need to be stored in the string?
Pseudo Code
Pseudo code:
Convert(x, buf) If x is negative x = x * 1 remember x was negative while there are digits in x digit = last digit of x buf = buf + digit; x = x / 10 if x was initially negative buf = buf + ‘‘ reverse buf
Assumptions/Limitations
Assumption/Limitation:
 We will assume the given number is an integer.
 Our program will also handle negative integers.
Major Data Structures
Major data structures:
Array of characters (string).
.
Unit tests:  
Postive Functional Test cases  
Input  Expected Output 
X = 1  “1” 
X = 0
X = 1234 X = 12345

“0”
“1234” “12345” 
Negative Functional Test Cases  
313158205942551  Overflow 
Here is the sample answer that implements the solution described above
#include <cstdio> #include <string.h> using namespace std; char array[100]; void convert(int x, char *buf) { // remember if the number is negative, so we can add '' at the end bool negative = false; if (x < 0) { negative = true; x *= 1; } // append digits to array of chars one by one, in reverse order int digit; while(x) { digit = x % 10; buf[strlen(buf)] = digit + '0'; x = x / 10; } // add the '' if necessary if (negative) buf[strlen(buf)] = ''; // reverse the string strrev(buf); } int main() { int number = 318513513; convert(number, array); printf("Here is the converted number: %s\n", array); return 0; }
Output and Further Excercise
Output:  Further exercise: 
318513513
Here is the converted number: 318513513

Q: How to we convert the number back to its integer representation?
A: We iterate through the string, and add them to an integer, initially set to 0. For example, given “1443” we would do the following steps: Assign 1 to the integer, multiply it by 10, add 4, multiply by 10, add 4, and so on. We also need to keep track of the sign and multiply the integer in the end.
