convert this C++ codes in C language       #include #include using namespace std;   const string EMPTY = "";   const string X[] = { EMPTY, "One ", "Two ", "Three ", "Four ", "Five ",                 "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ",                 "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ",                 "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen " };   const string Y[] = { EMPTY, EMPTY, "Twenty ", "Thirty ", "Forty ", "Fifty ",                 "Sixty ", "Seventy ", "Eighty ", "Ninety " };   // Function to convert a single-digit or two-digit number into words string convertToDigit(int n, string suffix) {     // if `n` is zero     if (n == 0) {         return EMPTY;     }       // split `n` if it is more than 19     if (n > 19) {         return Y[n / 10] + X[n % 10] + suffix;     }     else {         return X[n] + suffix;     } }   // Function to convert a given number (max 9-digits) into words string convert(unsigned long long int n) {     // string to store word representation of the given number     string res;       // this handles digits at ones and tens place     res = convertToDigit((n % 100), "");       if (n > 100 && n % 100) {         res = "and " + res;     }       // this handles digit at hundred place     res = convertToDigit(((n / 100) % 10), "Hundred ") + res;       // this handles digits at thousand and tens thousand place     res = convertToDigit(((n / 1000) % 100), "Thousand ") + res;       // this handles digits at hundred thousand and one million place     res = convertToDigit(((n / 100000) % 100), "Lakh, ") + res;       // this handles digits at ten million and hundred million place     res = convertToDigit((n / 10000000) % 100, "Crore, ") + res;       // this handles digits at ten million and hundred million place     res = convertToDigit((n / 1000000000) % 100, "Billion, ") + res;       return res; }   // C++ program to convert numbers to words int main()

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

convert this C++ codes in C language

 

 

 

#include <iostream>
#include <string>
using namespace std;
 
const string EMPTY = "";
 
const string X[] = { EMPTY, "One ", "Two ", "Three ", "Four ", "Five ",
                "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ",
                "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ",
                "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen " };
 
const string Y[] = { EMPTY, EMPTY, "Twenty ", "Thirty ", "Forty ", "Fifty ",
                "Sixty ", "Seventy ", "Eighty ", "Ninety " };
 
// Function to convert a single-digit or two-digit number into words
string convertToDigit(int n, string suffix)
{
    // if `n` is zero
    if (n == 0) {
        return EMPTY;
    }
 
    // split `n` if it is more than 19
    if (n > 19) {
        return Y[n / 10] + X[n % 10] + suffix;
    }
    else {
        return X[n] + suffix;
    }
}
 
// Function to convert a given number (max 9-digits) into words
string convert(unsigned long long int n)
{
    // string to store word representation of the given number
    string res;
 
    // this handles digits at ones and tens place
    res = convertToDigit((n % 100), "");
 
    if (n > 100 && n % 100) {
        res = "and " + res;
    }
 
    // this handles digit at hundred place
    res = convertToDigit(((n / 100) % 10), "Hundred ") + res;
 
    // this handles digits at thousand and tens thousand place
    res = convertToDigit(((n / 1000) % 100), "Thousand ") + res;
 
    // this handles digits at hundred thousand and one million place
    res = convertToDigit(((n / 100000) % 100), "Lakh, ") + res;
 
    // this handles digits at ten million and hundred million place
    res = convertToDigit((n / 10000000) % 100, "Crore, ") + res;
 
    // this handles digits at ten million and hundred million place
    res = convertToDigit((n / 1000000000) % 100, "Billion, ") + res;
 
    return res;
}
 
// C++ program to convert numbers to words
int main()
{
    cout << convert(99) << endl;
    cout << convert(1000) << endl;
    cout << convert(14632) << endl;
    cout << convert(997751076) << endl;
    cout << convert(2147483647) << endl;
 
    return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY