Dev Skill DCP-34: Number of Digits Solution(Count number of digits)

Problem link
Dev Skill DCP-34: Number of Digits Solution
#include<bits/stdc++.h>
using namespace std;
int count(int n)
{
    int t=0;
    if(n==0)
        return 1;
    while(n>0)
    {
        t++;
        n=n/10;
    }
    return t;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<count(n)<<endl;
    }
    return 0;
}

No comments

Theme images by enjoynz. Powered by Blogger.