Smith is a course instructor of cpp programming and currently he is teaching conversions to his students. He started with the basic programs and now he want to introduce some complex problems. Before starting the complex problems, he wants to start with high difficulty level problem, such as: counting the digits of a number. Help Mr. Smith to write a program which will accept one integer argument and returns count of digits of that argument using class to class conversion.
#include <iostream>
#include <string>
int main(){
int x;
std::cout<<"Enter the number(integer): ";
std::cin>>x;
std::cout<<"The count of digits in "<<x<<" is ";
std::cout<<std::to_string(abs(x)).length();
return 0;
}
Comments
Leave a comment