C Program to count number of digits in given number using While loop
Write C Program to count number of digits in given number using While loop
//Write a C program to count number of digits in given number #include <stdio.h> int main() { long int n, m; int count = 0; printf("Enter the number :--> "); scanf("%ld", &n); m = n; while(n > 0) { n = n / 10; count = count + 1; //count digits } printf("Number of digits in %ld :--> %d",m, count); return 0; }
Output:
Enter the number :--> 654321
Number of digits in 654321 :--> 6