Data Structures Lab 9: Iqra Rizwan Ahmed REG# 51539 BSCS 3D

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

DATA STRUCTURES LAB 9

Iqra Rizwan Ahmed


REG# 51539 BSCS 3D
Task 2:
#include <iostream>
using namespace std;

int fib(int n){


if (n == 1 || n == 2){
return 1;
}
else
return (fib(n - 1) + fib(n - 2));
}
int main(){
int a;
cout << "enter length of fibonaccci series: " << endl;
cin >> a;
for (int i = 1; i<= a; i++){
cout << fib(i);
}
}

TASK 1:
#include <iostream>
using namespace std;

#include<iostream>
using namespace std;

int fac(int n);

int main()
{
int n;

cout << "Enter a positive integer: ";


cin >> n;

cout << "Factorial of " << n << " = " << fac(n) << endl;

return 0;
}

int fac(int n)
{
if (n > 1)
return n * fac(n - 1);
else
return 1;
}

You might also like