C++ PROGRAM TO COUNT THE NUMBER OF DIGITS IN AN INTEGER
Sample Test Case : Enter a Number : 2345
Sample Output : Number of digits in the given number is 4
CODE
#include <iostream>
using namespace std;
int main()
{
int num,digit=0;
cout<<"Enter a Number :";
cin>>num;
while(num!=0)
{
num/=10;
digit++;
}
cout<<"Number of digits in given number is "<< digit;
return 0;
}

No comments:
Post a Comment