codinasion-archive / codinasion-monorepo

Community Monorepo
https://codinasion.org
MIT License
52 stars 167 forks source link

[Program]: Write a GO program to find average of digits of a number by recursion #4016

Closed harshraj8843 closed 1 year ago

harshraj8843 commented 1 year ago

Description

Write a GO program to find average of digits of a number by recursion

Average of digits of a number is the sum of digits of the number divided by the number of digits in the number. For example, the average of digits of 123 is 6. The sum of digits of 123 is 6 and the number of digits in 123 is 3. So, the average of digits of 123 is 6/3 = 2.

Input  : 123
Output : 2
How to contribute - Save the solution in `program/program/find-average-of-digits-of-a-number-by-recursion/find_average_of_digits_of_a_number_by_recursion.go` file
cacti23 commented 1 year ago

!assign

apurvagandhi commented 1 year ago

!assign

apurvagandhi commented 1 year ago

This program already exists in the project. This issue should be marked as resolved.

harshraj8843 commented 1 year ago

Hey @apurvagandhi, thanks for reporting this 👍🏻

If you like, you can improve the code to work with recursion https://github.com/codinasion/codinasion/blob/master/program/program/find-average-of-digits-of-a-number-by-recursion/find-average-of-digits-of-a-number-by-recursion.py

def average_of_digits(n):
    if n == 0:
        return 0
    digits = [int(d) for d in str(n)]
    return sum(digits) / len(digits)

print(average_of_digits(123))
AshitaSingamsetty commented 1 year ago

!assign

MadhuS-1605 commented 1 year ago

!assign

MadhuS-1605 commented 1 year ago

@harshraj8843 there's already a file available for the above issue, do i need to open a new PR for the same ?

harshraj8843 commented 1 year ago

No, Thanks for reporting 👍🏻

File Link: https://github.com/codinasion/codinasion/blob/master/program/program/find-average-of-digits-of-a-number-by-recursion/find_average_of_digits_of_a_number_by_recursion.go