write a program to sum of its digit with using control
structure or with out using loop. for ex: let the number is
25634 then answer will be=2+5+6+3+4=20

Answer Posted / lalabs

// assume that num is non-negative.

int sum_digits_recursive ( int num )
{
if ( num == 0 ) return 0;
return (num % 10 + sum_digits_recursive ( num / 10 ));
}

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

List the difference between a 'copy constructor' and a 'assignment operator' in C?

629


Tell me what is null pointer in c?

601


general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only

576


What is a dynamic array in c?

585


What is a macro?

647






what are enumerations in C

716


What is modifier & how many types of modifiers available in c?

596


How do you do dynamic memory allocation in C applications?

622


When should structures be passed by values or by references?

572


What is c system32 taskhostw exe?

576


How do you list files in a directory?

553


How can I find the modification date and time of a file?

595


‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

1867


Can we change the value of #define in c?

578


How can I remove the leading spaces from a string?

623