Answer to Question #328632 in C++ for Nickname

Question #328632

Write a C++ program and flowchart to count number of digits in a number

1
Expert's answer
2022-04-14T06:16:16-0400











#include <iostream>


using namespace std;


int countDigits(int number)
{
	int digit;
	int counter=0;
	while(number)
	{
		digit=number%10;
		number=number/10;
		counter++;
	}
	return counter;
}


int main(){
	int number;
	cout<<"Enter any positve integer number: ";
	cin>>number;
	cout<<"The number of digits in a decimal number is: "<<countDigits(number)<<"\n\n";
	system("pause");
	return 0;
}

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
APPROVED BY CLIENTS