Answer to Question #277831 in C++ for Ruba

Question #277831

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.

1
Expert's answer
2021-12-09T17:34:23-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog