Key Features

Experienced Teachers
Smart Classes
Regular Test
Study Material

Well qualified teachers with industrial experience.

To visualise or understand topics very easly.

We are organizing online and offline regular test.

We are providing prescribed study material.

Friday, October 30, 2020

Write a C Program to Count Number of Digits in an Integer.

/*

Write a C Program to Count Number of Digits in an Integer.
*/

#include <stdio.h>
int main()
{
            long long num;
             int count = 0;
            /* Input number from user */
            printf("Enter any number: ");
            scanf("%lld", &num);
            /* Run loop till num is greater than 0 */
            while(num != 0)
            {
                         /* Increment digit count */
                        count++;
                        /* Remove last digit of 'num' */
                         num /= 10;
            }
            printf("Total digits: %d", count);
            return 0;
}

OUTPUT :
Enter any number: 45698
Total digits: 5

Thank you very much for reading carefully, if you have any other questions, you can share it with us through comments, if this information was important to you, please let us know through comments.

Please do comment and share.
Thank You.

No comments:

Post a Comment