answersLogoWhite

0


Best Answer

int sumDigits(int n) {
int sum = 0;

while( n > 0 ) {
sum += (n % 10); // add last digit of n to sum
n /= 10; // divide n by 10 to "chop off" the last digit

}

return sum;

}

____________________________________________________

C program to find the sum of entered digit: By Jatinder Pal Singh

#include
#include
void main()
{
clrscr();
int n,num,x,sum=0;
printf("Enter a number=");
scanf("%d",&n);
while(n>0)
{
x=n%10;
sum=sum+x;
n=n/10;
}
printf("Sum of digits of a number=%d",sum);
getch();
}
User Avatar

Wiki User

โˆ™ 2009-09-25 12:16:57
This answer is:
User Avatar
Study guides

Data Science

โžก๏ธ
See all cards
4.29
โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…
7 Reviews

Add your answer:

Earn +20 pts
Q: Write a c program to compute the sum of digits of a given integer number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Flowchart to find the sum of digits of an integer number?

the sum of individual digits of a given integer number


Is 0.50 a integer number?

Any number that has non-zero digits after the decimal point is NOT an integer.


What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


How do you make a program that counts how many times each digit occured in the integer?

To count the number of times a digit occurs in an integer, start by initializing an array of ten counts of digits, such as int digits[10];Then, in a loop while the number is non zero, increment the element in the digits array that corresponds to the units digit, and then divide the number by ten, such as digits[number%10]++ and number/=10;int digits[10];int i;int number = some number;for (i=0; i


Is 3.14 an integer?

Any number that has non-zero digits after the decimal point is NOT an integer.


Is 1.50 an integer?

Any number with non-zero digits after the decimal point is NOT an integer.


Is 4.9 an integer?

Basically, an integer is a number that does NOT have digits after the decimal point (nor should it have a fractional part).


Is 0.6666666667 an integer?

No; an integer is a number without decimal digits, or without a fractional part.


What number has two digits has 11 as a factor and the sum of the digits is 13?

No integer fits those conditions.


Write a recursive method to compute the number of digits in a positive integer?

Such a method could be: public int NumberOfDigits(int num) { num = num/10; if( num == 0) return 1; return ( 1+NumberOfDigits(num) ); }


What is an integer number?

Basically a number without decimals (digits after a decimal point). this can be either positive or negative.


What is a multi digit number?

A number with more than one digits: that is, an integer greater than 9.

People also asked