Question: Write a programm in C to find sum of square of digit of the number.
#include
int main() {
int num1,sum=0,rem;
printf("Enter num1 \n");
scanf("%d",&num1);
while(num1 !=0)
{
rem=num1%10;
sum=sum+(rem*rem);
num1=num1/10;
}
printf("Sum of square of digit: %d\n",sum);
return 0;
}
Output:
Enter num1
23
Sum of square of digit: 13
#include
void squareDigit(int num)
{
int sum=0,rem;
while(num !=0)
{
rem=num%10;
sum=sum+(rem*rem);
num=num/10;
}
printf("Sum of square of digit: %d\n",sum);
}
int main() {
int num1;
printf("Enter num1 \n");
scanf("%d",&num1);
squareDigit(num1);
return 0;
}
Output:
Enter num1
13
Sum of square of digit: 10
Comments
Post a Comment