Answers for "how to find the sum of the digits of a number"

0

c program to find the sum of given number

# include<stdio.h>
int main
{
int number;
int sum=0;
int remainder;
printf("enter a number\n");
scanf("%d",&number);
for(;number!=0;)
{
remainder=number%10;
sum=sum+remainder;
number=number/10;
}
printf("sum of digits=%d",sum);
}
Posted by: Guest on June-22-2020
0

sum the digits of an integer

def getSum(n)
  n.digits.sum
end

print "Sum of digits = ", getSum(555);
Posted by: Guest on May-27-2021

Code answers related to "how to find the sum of the digits of a number"

Python Answers by Framework

Browse Popular Code Answers by Language