Write a C++ program and flowchart to count number of digits in a number
#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;
}
Comments
Leave a comment