Documente Academic
Documente Profesional
Documente Cultură
Lab Report#7
Class: BSSE-3A(Morning)
Roll No:11982
CODE:
#include<iostream>
int nmbr;
node* next;
node* prv;
};
node* head; //we take two pointers of node type to point the nodes of list.
node* tail;
void Insert(int x){//this function store data and address in the nodes.
node* temp=new node();//we take a temporary pointer of node type and store address of
the node created.
temp->nmbr=x;
temp->next=NULL;
temp->prv=NULL;
tail=temp;//we point both head and tail pointers to the first node.
head=temp;
else{ //if any address is stored in head than this statement is executed.
tail->prv=temp; //here the address of the node is stored in the previous block of
previous node.
temp->next=tail;
tail=temp;
void show(char ch){ //this functions prints our list on the screen.
node* temp1;
if(ch=='f'){ //if user want to print in forward direction than this block is executed.
cout<<temp1->nmbr<<" ";
} }
else{
while(temp1!=NULL){
cout<<temp1->nmbr<<" ";
temp1=temp1->next;
} }
int main(){
head=NULL;
tail=NULL;
char c;
Insert(2);
Insert(7);
Insert(0);
Insert(4);
cout<<"\nEnter the way you want your list to be shown....Note:f for forward and r for
reverse:",cin>>c;
show(c);
Delete();
cout<<"\nAfter deletion:\n";
show(c);
OUTPUT:
Q2. Write a program which perform factorial, power and Fibonacci series using Recurrsion.
CODE:
#include<iostream>
int factorial(int x){ //this function prints the factorial of the number user entered.
return x*factorial(x-1); //the function is called again and the value of x is decremented.
return 1;
}}
int power(int n, int pow ,int p){ //this function calculates the power of a number user entered.
return pow;
} }
if(x==0 || x==1){ //if x is equal to 0 or 1 then this statement executes and returns the
value of x;
return x;
}
else{
}}
int main(){
int nmbr;
int p;
cout<<"Enter a number:",cin>>nmbr;
cout<<"\n\n";
cout<<"\nEnter a number:",cin>>nmbr;
cout<<"Enter power:",cin>>p;
int i=nmbr;
cout<<"\n\n";
cout<<"\nEnter a number:",cin>>nmbr;
OUTPUT:
Q3. Write a program to print the given series using recursion.
CODE:
#include<iostream>
static int a=-10; //we create two static global variables so that there values can’t be changed.
int series(int i){ //this functions prints the required series using recurrsion
return 0;
else{
if(i>0 && i<10){ //when this condition is true, it prints number from 1 to 9.
cout<<i<<" ";
series(i+1); //the function is called again and we increment thee value of i in the
parameters.
int main(){
series(1);
OUTPUT: