Friday, February 1, 2019

Sum of Squares of Each Digit

  • Problem Description

    Write a program to read a positive integer and find the sum of squares of individual digits.
  • CODING ARENA
  • n=int(input())
    tot=0
    while(n>0):
        dig=n%10
        tot=tot+dig*dig
        n=n//10
    print(tot)
  • Test Case 1

    Input (stdin)
    8974
    
    
    Expected Output
    210
  • Test Case 2

    Input (stdin)
    5398
    
    
    Expected Output
    179

No comments:

Post a Comment