Count number of digits in a number
    Sample Output
        Count number of digits in a number. Enter number: 192002024 Total 9 digit(s). Process returned 0 (0x0) execution time : 12.468 s Press any key to continue.
Source Code 
        #include<stdio.h>
int main()
{
    int n, num, count = 0;
    printf("Count number of digits in a number.\n");
    printf("\nEnter number: ");
    scanf("%d", &num);
    
    for(n = 1; num != 0; n++)
    {
        num = num / 10;
        count++;
    }
    printf("\nTotal %d digit(s).\n", count);
    
    return 0;
}
    Sample Output
        Count number of digits in a number. Enter number: 6789 Total 4 digit(s). Process returned 0 (0x0) execution time : 6.375 s Press any key to continue.
No comments:
Post a Comment