Find Sum of square of digit of number in C by R4R Team

Example-
number is: 342
then sum of square of digit is 29

program-

#include< stdio.h>
int main()
{
int n,sum=0;
printf("Enter number\n");
scanf("%d",&n);
while(n)
{
sum=sum+(n%10)*(n%10);
n=n/10;
}
printf("Sum of sqaure of digit is %d",sum);
}


output-

Enter number
22
Sum of square of digit is 8
Enter number
34
Sum of sqaure of digit is 25

-In this program, we take an input of the integer number in variable 'n',
-then we run the while loop to break each digit of the number and add in sum variable with square.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!