Jane and james are friends and both are really interested in learning new aspects and new things in a programming language. One day, they planned to find out the best algorithm to count the frequency of each digit in any given number. Help them find out the best algorithm to do the same.
Answers
Answered by
3
The best algorithm is to extract the last digit of a given number by performing the modulo operation of the given number by 10.
Explanation:
- The last digit of the number is represented as digit D.
- Let the number be n.
- Then extraction process occurs where d= n % 10.
- If the d =D, where the extracted digit is equal to the digit for which the frequency has to be determined, then an increment operation is done.
- This loop continues until the desired result is obtained
To know more:
1) Write a program in c to accept a number and display the digits in words?
https://brainly.in/question/7303393.
2) Wap to input an integer and display the frequency of each digit in that integer. plz solve and send the full prog...very argent for computer project....
https://brainly.in/question/4831550
Answered by
9
Answer:
Algorithm of finding the count of the frequency of each digit in any given number.
START
Take the number N and the digit D from the user.
Keep extracting digits from the number N and check the extracted digits with the given digit D
Check If the extracted digit equals to the digit D then increment the count.
while ( N > 0) {
if ( N % 10 == D )
count ++ ;
N = N / 10 ;
}
END
Explanation:
Similar questions