0% found this document useful (0 votes)
2 views2 pages

Recursion Programs

The document contains two C programs demonstrating recursion. The first program prints the Fibonacci series for a user-defined number of terms, while the second program calculates the sum of the digits of a given number. Both programs include necessary functions and user input prompts.

Uploaded by

Sachin Samriddh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Recursion Programs

The document contains two C programs demonstrating recursion. The first program prints the Fibonacci series for a user-defined number of terms, while the second program calculates the sum of the digits of a given number. Both programs include necessary functions and user input prompts.

Uploaded by

Sachin Samriddh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Structures using C Lab Date:- 04.12.

2024

1. Write a program in C to print the Fibonacci Series using recursion.


int term;
int fibonacci(int prNo, int num);

void main()
{
int prNo = 0, num = 1;
printf("\n\n Recursion : Print Fibonacci Series :\n");

printf(" Input number of terms for the Series (< 20) : ");
scanf("%d", &term);
printf(" The Series are :\n");
printf(" 1 ");
fibonacci(prNo, num);
printf("\n\n");
}

int fibonacci(int prNo, int num)


{
static int i = 1;
int nxtNo;

if (i == term)
return (0);
else
{
nxtNo = prNo + num;
prNo = num;
num = nxtNo;
printf("%d ", nxtNo);

i++;
fibonacci(prNo, num); //recursion, calling the function fibonacci itself
}
getch();
return (0);
2. Write a program in C to find the sum of digits of a number using recursion.
#include <stdio.h>
#include<conio.h>

int DigitSum(int num);

int main()
{
int n1, sum;
clrscr();
printf(" Input any number to find sum of digits: ");
scanf("%d", &n1);

sum = DigitSum(n1);//call the function for calculation

printf(" The Sum of digits of %d = %d\n\n", n1, sum);


getch();
return 0;
}

int DigitSum(int n1)


{
if(n1 == 0)
return 0;

return ((n1 % 10) + DigitSum(n1 / 10));


}

You might also like