C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
FIND SUM OF DIGITS OF A NUMBER USING RECURSION USING C PROGRAM
Sum of n numbers using recursion in c
Matrix multiplication using recursion in c
Multiplication using recursion in c
Lcm using recursion in c
Using recursion in c find the largest element in an array
Prime number program in c using recursion
Decimal to binary conversion in c using recursion
C program for fibonacci series using recursion
Reverse a string using recursion
Write a program for palindrome using recursion
Find factorial of a number using recursion in c program
Find gcd of a number using recursion in c program
Find sum of digits of a number using recursion using cprogram
Find power of a number using recursion using c program
Binary search through recurssion using c program
Reverse a number using recursion in c program
Big list of c program examples
Subscribe to:
Post Comments (Atom)
12 comments:
write a program to add the following
¼+2/4+3/4+5/3+6/3+………
You should declare function int findsum(int) and line 18 (else) shouldn't be included, because the output is incorrect...here is the right source code:
#include
int findsum(int);
int main(){
int num,x;
printf("\nEnter a number: ");
scanf("%d",&num);
x=findsum(num);
printf("Sum of the digits of %d is: %d",num, x);
return 0;
}
int r, s;
int findsum(int n){
if(n){
r=n%10;
s=s+r;
findsum(n/10);
}
return s;
}
s should be initialized with 0
No need as it is global so already initialized with 0.
initialize with zero
ya u r right...
The variable s treats as a external variable.the default value of s is automatically initialized to 0.
what's the meaning of if (n) ??
how will you find the sum of the digits of the resulting sum of digits if it is more than 10?
int sum = 0;
if (num < 10)
return num;
else
{
sum = num % 10;
num = num / 10;
num = num + sum;
return Add_Digits(num);
}
its global variable
its initialize with 0 by default
Post a Comment