top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to convert a number into string i.e. 1234 to one two three without using if or switch statement?

+2 votes
608 views
How to convert a number into string i.e. 1234 to one two three without using if or switch statement?
posted Dec 3, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

When we write 1234 to one two three four then we need to first get 1 followed by 2 and so on. Once we get that its easy we can replace the text as follows -

int main()
{
    int n = 1234;
    char word[][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    //  first reversing the number to output from front

    int reverse = 0;
    while (n != 0)
    {
        reverse = reverse * 10;
        reverse = reverse + n%10;
        n = n/10;
    }

    //  now outputting the word

    while (reverse != 0)
    {
        printf("%s ", word[reverse % 10]);
        reverse /= 10;
    }
}
answer Dec 4, 2015 by Salil Agrawal
Similar Questions
+8 votes

Convert the given string into palindrome with minimum number of appends(at end of the given string). O(n) algorithm will be appreciated ??

Input :=> Malayal
Output :=> Malayalam

+3 votes

I need help in writing the code where I enter the input in which each char is followed by its occurrence and output should be absolute string.

Example
Input a10b5c4
Output aaaaaaaaaabbbbbcccc

–1 vote

Write a C program to check if the given string is repeated substring or not.
ex
1: abcabcabc - yes (as abc is repeated.)
2: abcdabababababab - no

...