answersLogoWhite

0


Best Answer

Repeatedly divide by the base until the number is 0, counting the number of divisions as you go.

int count_digits (int n, int base=10) { // default to decimal notation

if (base<2) {/* handle invalid argument */}

int count=0;

while (n!=0) {

n/=base;

++count;

}

return count;

}

Note that the value 0 has no digits. If you wish to count 0 as a digit, alter the algorithm as follows:

int count_digits (int n, int base=10) { // default to decimal notation if (base<2) {/* handle invalid argument */}

int count=0;

do {

n/=base;

++count;

} while (n!=0);

return count;

}

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the c program to count the no of digits in the given number in proper formatted way?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

In a measurementwhich digits isare an approximation?

In a measurement the digits that are an approximation are only those in proper scientific notation. The more digits that are added to the number the more the number becomes exact.


What are the proper waste on writing a number in scientific notation?

Writing a string of random digits is a proper waste!


How many significant figures are in the number 0.05?

Only one. The zeros are there to put the 5 into its proper position; they are not significant digits.


What happens if 1 of your lottery Number digits match the winning numbers?

Nothing, unless all the others match up in the proper order.


What is the greatest proper fraction that has 3 different digits?

In a proper fraction the numerator is smaller than the denominator. Since every two-digit number is larger than every one-digit number, there must be a one-digit numerator and two-digit denominator comprising 3 digits total. The greatest fraction will be the one with the largest possible numerator and smallest possible denominator. Choose a numerator of 9 (the largest one-digit number) and a denominator of 10 (the smallest 2-digit number). All 3 digits are different. The answer is 9/10.


How to turn a fraction to a decimal?

, divide the numerator by the denominator. To change terminal decimals into fractions, count the number of decimal places, put the decimal's digits over 1 followed by the proper number of zeroes.


What is the greatest proper fraction that has 7 different digits?

It is 987/1234.


What is the greatest proper fraction that has 5 different digits?

98/103 98/102 can be simplified and so is not proper.


What is the product of the number 1000 and the measurement 0.00357 m expressed in the correct number of sisgnificant digits?

multiplying by a 1000, just move the decimal point 3 places to the right. 3.57. This is the proper number of sig figs as well.


When is a number significant or not significant?

Any non-zero digit is significant. Example: 352.12 has 5 significant digits. A zero is significant if it appears between non-zero digits. Example: 504.2 has 4 significant digits. A zero is also significant when it appears after the decimal point, AFTER other digits. In this case, it was only added to indicate a significant digit. Example: 5.30 has 3 significant digits. A zero after other numbers may or may not be significant. Use scientific notation to unambiguously indicate the number of significant digits. Example: 4500 has 2 significant digits. It may have 3 or 4 significant digits, but to be safe, assume 2 significant digits. A zero is NOT significant if it comes after the decimal point, BEFORE any other digits. In this case, it is only used to put the digits in their proper place. Example: 0.0024 has 2 significant digits.


Why there are quadrilaterals in infrastructure?

check your infrastructure, if it was formatted to the proper calibur the quadrelaterals should be one zenith proaction away form the articulated redundencies


What is a positive release program?

The proper material in the proper amount going to the proper customer in the proper manner is the focus of the Positive Release program, a multi-corporate initiative to insure On Time, In Full, with No Errors (OTIFNE).