Write a program to count number of digits in a decimal number.
#include<stdio.h>
int countDigits(int number)
{
int digit;
int counter=0;
while(number)
{
digit=number%10;
number=number/10;
counter++;
}
return counter;
}
int main(){
int number;
printf("Enter any positve integer number (7 digits): ");
scanf("%d",&number);
printf("The number of digits in a decimal number is: %d\n\n", countDigits(number));
scanf("%d",&number);
return 0;
}
Comments
Leave a comment