[go: up one dir, main page]

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

DSA p7

The document provides implementations of recursive functions for calculating the factorial and generating the Fibonacci series in C++. It includes code snippets for both functions and prompts the user for input to display the results. The document is part of a practical exercise for a data structures and algorithms course.

Uploaded by

patel.shivam1712
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)
11 views2 pages

DSA p7

The document provides implementations of recursive functions for calculating the factorial and generating the Fibonacci series in C++. It includes code snippets for both functions and prompts the user for input to display the results. The document is part of a practical exercise for a data structures and algorithms course.

Uploaded by

patel.shivam1712
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

PRACTICAL-7

AIM : Implement recursive functions.

INPUT:

Factorial :-

#include<iostream.h>
#include<conio.h>
long long fact(int n)
{
if(n==0 || n==1)
{
return 1;
}
return n * fact(n-1);
}
void main()
{
int n;
clrscr();
cout<<"Enter number for factorial:";
cin>>n;
cout<<fact(n);
getch();
}

OUTPUT:

Data structure and algorithm (4330704) Enrollment No : 239830331099


Fibonacci:-

#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int n,i,t1=0,t2=1,nextterm;
cout<<"Enter number for fibbonacci series:";
cin>>n;
cout<<"Fibonacci series is:\n";
for(i=1;i<=n;++i)
{
cout<<t1<<" ";
nextterm=t1+t2;
t1=t2;
t2=nextterm;
}
return 0;
getch();
}

OUTPUT:

Data structure and algorithm (4330704) Enrollment No : 239830331099

You might also like