Pages

Wednesday, August 17, 2016

C program to count no. of digits in a given number.

#include <stdio.h>
int main()
{
  int number, count=0;
  printf("Enter your number: ");
  scanf("%d", &number);
  while(number!=0)
  {
      number = number / 10;   
      count = count + 1;
  }
  printf("Number of digits = %d", count);
  return 0;
}

Output of the Program:

Enter your number: 10123
Number of digits = 5



No comments:

Post a Comment