answersLogoWhite

0


Best Answer

def digits(x):
""" Return amount of digits of x. """
y = math.log10(x)
if y % 1 0:
return int(y)
else:
return int(math.floor(y) + 1)

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

for (revn=0; n!=0; n/=10) revn = 10*revn + n%10;

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Algorithm to count the digits in a given number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you write an assembly language program to count the number of ones in a given byte?

1. Find algorithm.2. Implement it.Hint: if a non-zero N number has K 1-bits, then (N AND N-1) has K-1 1-bits.


Write algorithm to find the sum of the digits in a given 4 digit no ex- no is 8516 then 8 5 1 6?

I cannot do your homework, if you cannot explain it properly.


How do you write an algorithm to find the number of times a given ITEM occurs in LIST?

You can write any algorithm in any way you like. Many prefer pseudocode or flowcharts, others use prose or more formalized methods. For example, if you wanted to describe an algorithm to count the number of occurrences of a given item I in a given list L, I would propose the following pseudocode: let counter be 0. let the current item C be the first item in list L. while C == valid { if C matches I then increment counter set C to the next item in the list } return counter.


A Write the algorithm to concatenate two given strings?

a write the algorithm to concatenate two given string


What are the characteristics of an algorithm. Describe with an example?

An algorithm is a stepwise sequence of operations that can be performed to solve a problem. The operations are expected to be 'simple', so they can be performed mechanically.A simple example algorithm is "how to find the largest number in a list of numbers":- look at the first number and write it down as the largest-so-far- for each remaining number in the list:- - replace largest-so-far with this number if this number is larger- when you have compared all the numbers, largest-so-far is the largest number in the listA less trivial algorithm is the one people learn in school for multiplying multi-digit numbers, called "long multiplication" or "grade-school multiplication". It becomes rather long if you write down all the steps (as you would need to for an algorithmic description), but it involves multiplying each digit in the first number with each digit in the second number and summing the partial results.Here the simple operation is multiplying two single digits, which you are expected to know how to do, and by using the algorithm you can extend the knowledge of how to multiply single digits to multiply numbers with any number of digits.See related links.

Related questions

How many significant digits in 500.95?

To assess the number of significant digits in a number, you first have to find the greatest non-zero digit. In this case it is the first five which represent 500. The next step is to simply count how many digits there are after this number. In this case, there are 4 more digits. Thus the number 500.95 has been given to 5 significant digits.


What is the c program to count the no of digits in the given number in proper formatted way?

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


Algorithm for to find sum of individual digits of a positive integer?

enter the number whose digits are to be added num is the given value num=0! k=num%10 sum=sum=k k=num/10 num=k print the sum of the digits


How many significant are in 14500?

There are 5 significant digits in number 14500. To count for a given number as to how many significant digits does it have, look for the first zero form left and decimal point. For ex sample 0045 has 2 significant digits 0.0045 has 2 significant digits 0.4500 has 4 significant digits.


How many significant digits are in for this number 3.008?

All four of the digits given are significant digits.


How many significant digits are in 5.060?

The first step in assessing the number of significant figures is to identify the greatest non-zero digit. In this case it is five. Then you simply count on until the last digit given. In this case there are 3 more digits after the 5. Therefore the number has been given to 4 significant figures.


If a number with two digits is equal to four times the sum of its digits the number formed by reversing the order of the digits is 27 greater than the given number what is the number?

36


What is the smallest 5 digits odd number that can be formed with given digits 45083?

03458


Is a number with two digits is equal to four times the sum of its digits the number formed by reversing the order ofthe digits is 27 greater than the given number what is the number?

The number is 36.


The sum of the digits of a two digit number is 9 the number obtained by reversing the order of the digits of the gven numbers exceeds the given number by 27 find the given numbers?

3 and 6


How do you write an assembly language program to count the number of ones in a given byte?

1. Find algorithm.2. Implement it.Hint: if a non-zero N number has K 1-bits, then (N AND N-1) has K-1 1-bits.


Write algorithm to find the sum of the digits in a given 4 digit no ex- no is 8516 then 8 5 1 6?

I cannot do your homework, if you cannot explain it properly.