Thursday 3 October 2013

Counting digits of a number using C

#include<stdio.h>
main()
{
int n,count=0;
printf(" Enter an integer: ");
scanf("%d", &n);
while(n!=0)
{
n/=10; /* n=n/10 */ ++count; }
printf("\n Number of digits: %d \n",count);

No comments:

Post a Comment