I want to write a c program that prints the sum of the squares of a given number. For example, if the given number is 456, the output would be 4^2+5^2+6^2=16+25+36=77.
So i have written this code and i want to know why it doesn't work if the user gives a number like 100,101,102 or 200,300 etc. It works fine for other numbers. I guess it has something to do with the dowhile loop. Please help me.
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int n,t=0,r,q;
printf("Enter the number to be tested: ");
scanf("%d",&n);
q=n;
do
{
r=q%10;
t=t+pow(r,2);
q=q/10;
}
while(q%10!=0);
printf("%d",t);
getch();
}
while(q%10!=0);
be something likewhile(q>0);
? Otherwise it'll stop at a0
. – Biffen