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 Answer
- Comment
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:
ليست هناك تعليقات:
إرسال تعليق