0% found this document useful (0 votes)
21 views9 pages

DAA Practical 1

Daa practical 1

Uploaded by

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

DAA Practical 1

Daa practical 1

Uploaded by

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

Group A – Design and Analysis of Algorithm

Assignment No. 1
Fibonacci Program using Class and Object :

#include<iostream.h>
#include<conio.h>
class Fibonacci {
public:
int a;
int b;
int c;
void generate(int);
};
void Fibonacci::generate(int n)
{
a=0;
b=1;
cout<<a<<" "<<b;
for(int i=1;i<=n-2;i++)
{
c=a+b;
cout<<" "<<c;
a=b;
b=c;
}
}
int main()
{
int n=5;
clrscr();
Fibonacci fib;
fib.generate(n);

getch();
return 0;
}
Program:- Fibonnaci Series using Recursion in C++

#include<iostream.h>
#include<conio.h>

class fibonacci
{
public:
int x;
int generate(int);
};

int fibonacci::generate(int x)
{
if((x==0) || (x==1))
{
return x;
} else
{
return (generate(x-1) + (generate(x-2));
}
}
int main()
{

int i=0, n;
int ans;
cout<<"Enter the number: ";
cin>>n;
cout<<"fibonaccie series is: ";
fibonacci f;
while( i<n )
{
ans = f.generate(i);
cout<<ans;
i++;
}
getch();
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy