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

Can we increase size of array in c?

534


How can I split up a string into whitespace-separated fields?

566


find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }

1855


Write a program to implement queue.

664


Explain heap and queue.

577






Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays

1890


#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }

710


how to find binary of number?

3422


Write a program to print all permutations of a given string.

638


The file stdio.h, what does it contain?

665


What is nested structure with example?

620


Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

637


What is the size of a union variable?

597


What is a class c rental property?

605


Difference between strcpy() and memcpy() function?

673