answersLogoWhite

0

The following function will sum the digits in any positive number.

unsigned int sum_digits(unsigned int num, unsigned int base=10)

{

sum=0;

if(base>1) // base must be 2 or higher

{

while(num)

{

sum+=num%base; // add least significant digit to sum

num/=base; // shift right by base

}

}

return(sum);

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


How can you generate a palindrome from a given number?

You write the number and then follow it with the digits in reverse order.


Write a pseudo code to find the sum of digits of a given number reducing them to a single digit?

5


How many significant digits are in for this number 3.008?

All four of the digits given are significant digits.


Write a c program to find given number is prime or not?

Yes, do write, or if you're too lazy to your homework, use google.


Write a c program to add the digits of a given no?

THIS IS ONLY FOR UPTO A FIVE DIGIT NO. BY ROHAN ARORA#include#includevoid main(){int a,n,s,sum=0;clrscr();printf("Enter the number between 1 to 5 digits\n");scanf("%d",&a);while(a!=0){n=a%10;sum=sum+n;a=a/10;}printf("The sum of digits of the given numberis %d",sum);getch();}


Could you write a assembly language program in tasm To check whether a given number present in a sequence of given memory location containing the string to be checked in 8086?

8086 assembly language program to check wether given number is perfect or not


If a number with two digits is equal to four times the sum of its digits the number formed by reversing the order of the digits is 27 greater than the given number what is the number?

36


Include zeros in 2.25 million?

Million is the name given to a number with 7 digits in front of the decimal place. In order to write out any number take the number you are given and and move the decimal place to the right until you have 7 digits in front of the decimal. add zeros to the end until it has 7 digits in front of the decimal place. So 2.25 million would be 2,250,000.


What is the smallest 5 digits odd number that can be formed with given digits 45083?

03458


Is a number with two digits is equal to four times the sum of its digits the number formed by reversing the order ofthe digits is 27 greater than the given number what is the number?

The number is 36.


Write a C program to extract a given word from a file?

program to extract a given word from a file