0% found this document useful (0 votes)
46 views

#Include Void Int Int Int Long Int

The document contains code snippets demonstrating recursion to generate Fibonacci series and calculate factorials in C programming language. The Fibonacci series code uses a recursive function printFibonacci() to sequentially output terms by calling itself with the decremented parameter n until the base case of n being 0. Similarly, the factorial code uses a recursive fact() function that multiplies the input number n with the result of fact(n-1) until the base case of n being 1 is reached, at which point it returns 1.

Uploaded by

Veda Vyas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

#Include Void Int Int Int Long Int

The document contains code snippets demonstrating recursion to generate Fibonacci series and calculate factorials in C programming language. The Fibonacci series code uses a recursive function printFibonacci() to sequentially output terms by calling itself with the decremented parameter n until the base case of n being 0. Similarly, the factorial code uses a recursive fact() function that multiplies the input number n with the result of fact(n-1) until the base case of n being 1 is reached, at which point it returns 1.

Uploaded by

Veda Vyas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program to generate Fibonacci series using recursion in c #include<stdio.

h> void printFibonacci(int); int main(){ int k,n; long int i=0,j=1,f; printf("Enter the range of the Fibonacci series: "); scanf("%d",&n); printf("Fibonacci Series: "); printf("%d %d ",0,1); printFibonacci(n); return 0; } void printFibonacci(int n){ static long int first=0,second=1,sum; if(n>0){ sum = first + second; first = second; second = sum; printf("%ld ",sum); printFibonacci(n-1); } } Sample output: Enter the range of the Fibonacci series: 10 Fibonacci Series: 0 1 1 2 3 5 8 13 21 34 55 89

Recursive function for factorial in c #include<stdio.h> int fact(int); int main(){ int num,f; printf("\nEnter a number: "); scanf("%d",&num); f=fact(num); printf("\nFactorial of %d is: %d",num,f); return 0; } int fact(int n){ if(n==1) return 1; else return(n*fact(n-1)); }

You might also like