write a C program to calculate the sum of its digits
![c program to sum of digits of a 5 digit number c program to sum of digits of a 5 digit number](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_629,h_423/http://blog.eduguru.in/wp-content/uploads/2016/03/c-program-to-sum-of-digits-of-a-5-digit-number.png)
Problem Statement:
If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.
Answer:
/* Sum of digits of a 5 digit number*/
#include<stdio.h>
#include<conio.h>
main()
{
int num,a,n;
int sum=0; /* this has been initialised to zero otherwise it will contain a garbage value */
clrscr();
print(“\n Enter a 5 digit number less than 32767”);
scanf(“%d”, &num);
a=num % 10; /* last digit expected as remainder */
n=num/10; /*Remaining Digits */
sum=sum+a; /* sum updated with addition of extracted digit */
a=n % 10; /* 4rth digit expected as remainder */
n=n/10; /*Remaining Digits */
sum=sum+a; /* sum updated with addition of extracted digit */
a=n % 10; /* 3rd digit expected as remainder */
n=n/10; /*Remaining Digits */
sum=sum+a; /* sum updated with addition of extracted digit */
a=n % 10; /* 2nd digit expected as remainder */
n=n/10; /*Remaining Digits */
sum=sum+a; /* sum updated with addition of extracted digit */
a=n % 10; /* 1st digit expected as remainder */
sum=sum+a; /* sum updated with addition of extracted digit */
printf(“\n The sum of 5 digits of %d is %d”, num, sum);
printf(“\n\n\n\n Press any key to exit…”);
getch();
}