Create a programm with function( or functions) Write a digitCount function that gets a positive integer and returns the number of its digits. The program ends when the user presses the ESC key.
#include<iostream>
#include<string>
using namespace std;
int digitCount(int number){
string res = to_string(number);
return res.length();
}
int main(){
cout<<"Enter a number\n";
int n;
cin>>n;
cout<<"The number of digits in "<<n <<" are "<<digitCount(n)<<endl;
}
Comments
Leave a comment