Answer to Question #259599 in C for fas

Question #259599

Arjun wants to count total number of digits of an Integer number (N). Help him to generate the program using do while loop.



1
Expert's answer
2021-11-04T16:26:53-0400
#include <stdio.h>

int main()
{
    int number;
    int digits;
    
    printf("Input a integer: ");
    if(scanf("%d", &number) != 1)
    {
        printf("Bad input\n");
        return 1;
    }

    if(number == 0)
    {
        digits = 1;
    }
    else
    {
        digits = 0;

        while(number != 0)
        {
            digits++;
            number /= 10;
        }
    }

    printf("Total number of digits is %d\n", digits);

    return 0;
}

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