Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


C Program to Count number of Digits in a number using While Loop


The following example shows, how to count number of digits in a number using while loop in C program.

Example : pgm.c

#include<stdio.h>
int main()
{
  int num,count=0;
  printf("\nEnter Any Number : ");
  scanf("%d",&num);
  while(num!=0)
  {
      num=num/10;
      count++;
  }
  printf("\nNo of Digits : %d",count);
  return 0;
}

Output:

Enter Any Number : 85476
No of Digits : 5