Answer to Question #308234 in C for ahmed

Question #308234

Write a program to count number of digits in a decimal number.


1
Expert's answer
2022-03-17T06:42:12-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS