Answers for "sum of digits in c using for loop"

C
0

sum of digits in c using for loop

#include <stdio.h>
int main()
{
   int n, sum = 0, r;

   printf("Enter a number\n");

   for (scanf("%d", &n); n != 0; n = n/10) {
      r = n % 10;
      sum = sum + r;
   }

   printf("Sum of digits of a number = %d\n", sum);

   return 0;
}
Posted by: Guest on June-02-2021

Code answers related to "sum of digits in c using for loop"

Code answers related to "C"

Browse Popular Code Answers by Language