Answer to Question #332557 in C++ for micheal

Question #332557

Write a C++ program to count number of digits in a number n which will be input by the user.


1
Expert's answer
2022-04-22T14:25:28-0400
#include <iostream>

using namespace std;

int main()
{
	int n;
	cout << "Please, enter a number n: ";
	cin >> n;
	int i = 0;
	while (n > 0)
	{
		n /= 10;
		i++;
	}
	cout << "Number of digits in n is " << i;
}

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