(g) If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulus operator ‘%’)
Let Us C by Yashwant Kanetkar
Solution By Muhammad Kaleem UIlah
(g) If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulus operator ‘%’)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,a,b,c,d,e,f,g,h,sum;
printf("\n\t\t Enter Your Desire 5 Digit Number = ");
scanf("%d",&num);
a=num/10000;
b=num%10000;
c=b/1000;
d=b%1000;
e=d/100;
f=d%100;
g=f/10;
h=f%10;
sum=a+c+e+g+h;
printf("\n\t\t Sum of the Digits = %d",sum);
return 0;
}
Comments
Post a Comment