- ahmad alhayek

Write a c++ program that takes an integer num between 1 and 99999, then computes the number of digits in num. If the number exceeds 99999 or is less than 1, the program must output "False" to the user, otherwise, the output can be "One", "Two", "Three", "Four", or "Five".

Expert Answerinformation icon

  • Mohd Awes Shaikh's Avatar

    Explanation: I have implemented the code and have shown the output, please find the image attached with the answer. Please upvote if you liked my answer and comment if you need any explanation or modification

    Code:

    #include <iostream>
    using namespace std;

    int main ()
    {
    int number, count = 0;
    cout << "Enter an integer num between 1 and 99999 : ";
    cin >> number;
    if (number > 99999 || number < 1)
    cout << "False";
    else
    {
    while (number > 0)
    {
    number = number / 10;
    count++;
    }
    if (count == 1)
    cout << "One";
    else if (count == 2)
    cout << "Two";

    else if (count == 3)
    cout << "Three";
    else if (count == 4)
    cout << "Four";
    else if (count == 5)
    cout << "Five";
    }

    return 0;
    }

    Output:

    Enter an integer num between 1 and 99999 : 3456 Four .. Program finished with exit code 0 Press ENTER to exit console.

    input Enter an integer num between 1 and 99999 : 1000000 False ... Program finished with exit code 0 Press ENTER to exit cons

    Comment 

ليست هناك تعليقات:

إرسال تعليق

ahmad alhayek تصميم ahmad alhayek جميع الحقوق محفوظة 2016

صور المظاهر بواسطة sndr. يتم التشغيل بواسطة Blogger.