Write a program to accept any integer and find the sum of the square of each digit present in the
accepted number.
E.g : n=132=13+33+23=1+27+8
Output=36
Answers
The following codes have been written using Python.
We input the number using the input() function and call it with the int() data type to ensure that the data being input is an integer value. Once the data has been entered, we assign the variable 's' to print the final output. We start an iterative loop [a loop that is used to perform repeated checking] to traverse through the number, and assign s to the sum of its original value 0 and the digit's cube. We use the range for the loop as 'str(n)', i.e., converting the number into a string value, since an integer value cannot be traversed through. After the loop has been completed, it prints the final output, which the sum of each digit's cube.
Note: Despite the question asking for the sum of the square of each digit, I've made the program for the sum of the cube of each digit as in the sample given, the concept has been performed as per the cube of each digit. If you want the sum of the square of each digit, type 2 instead of 3 in the 4th line.