Count the numbers of digits in C
×


Count the numbers of digits in C

264

Declare an integer variable c to store the number.

 Initialize an integer digit Count to zero.

 Iterate through each digit of c:

 Increment digit Count for each digit encountered.

 Modify c by removing its last digit using division.

 Final Count: The digit Count will represent the number of digits in c.

Example Program in C:

// Program for count the numbers of digits in c
#include<stdio.h> 

int main() {
    int c = 45678;  // Your number goes here
    int digitCount = 0;

    // Count digits
    while(c != 0) {
        digitCount++;
        c /= 10;  // Remove the last digit
    }

    printf("The count of digits in %d is: %d\n", c, digitCount);

    return 0;
}

Output:

The count of digits in 45678 is: 5

 c is initialized with the value 45678.

 digit Count begins at 0 to track digits.

The while loop continues until c is reduced to 0:

 digit Count is incremented for each digit.

c is shortened by one digit through division by 10.

The output showcases digit Count, which signifies the count of digits in c.

Executing this C code will yield:

The count of digits in 45678 is: 5



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments