If a three-digit integer is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulo operator ‘%’)

int main()
{
   int num, sum=0;
   printf("Enter any three digit number: ");
   scanf("%d", &num);
   sum += num % 10;
   num = num / 10;
   sum+=num%10;
   num=num/10;
   sum+=num%10;
   printf("Sum of digits = %d", sum);
   return 0;
}

     
Next Post Previous Post
No Comment
Add Comment
comment url