Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Program to count how many integers from 1 to N contains 0's as a digit

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 531
    Comment on it
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n,remainder,cnt=0,i,temp1;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            temp1=i;
            while(temp1)
            {
               remainder=temp1%10;
               if(remainder==0)
               {
                    cnt++;
                    break;
               }
               temp1=temp1/10;
            }
        }
        printf("%d",cnt);
    }
    

    Input:

    110

    Output:

    20

    Explanation:

    For loop runs till entered number i.e n. Within for loop value of variable i is assigned to temp1 and while loop inside for loop runs till temp1 is true. A remainder is obtained by using modulus operator i.e temp1 % 10. A number if contain digit 0 when divided by 10 will give remainder 0 thus if condition is used to check value of remainder if 0 value of counter i.e cnt is incremented and finally dividing temp1 with 10. This procedure can be used to count number of integers from 1 to N contains 0's as a digit

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: