C program to find sum of square of digit.|without function| with Function.

Question: Write a programm in C to find sum of square of digit of the number.

Source Code:

#include <stdio.h> 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

Using Function:

#include <stdio.h> 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

Popular posts from this blog

Introduction to Python.

Decision Making Statement.