Accenture Coding Question | Adam’s Charity | CodeWindow

Adam’s Charity

Adam decides to be generous and do some charity. starting today, from day 1 until day n, he gives i^2 coins to charity on day ‘i’ (1<=i<=n).
return the total coins he would give to charity.

Input specification:
Input 1: number of days of Charity.

Output Specification:
Return the total number of coins till charity days.

Example 1:
Input 1: 2

Output: 5
Explanation:
There are 2 days.

Example 2:
Input 1: 3

Output: 14
Explanation:
There are 3 days.

Solution in Python 3:

# https://codewindow.in

n=int(input())
sum=0
for i in range(1,n+1):
    sum=sum+(i**2)
print(sum)

#join Telegram @codewindow

Output:

3
14
Recent Posts

Leave a Comment

Your email address will not be published. Required fields are marked *