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

Data Structures and Algorithms

Lab Journal - Lab 8

Name: Danish Tameez

Enrollment #: 01-235181-009

Class/Section: BSIT-3A
Question no1
#include <iostream>
#include <conio.h>
using namespace std;

int A(int m, int n)


{
if(m==0)
{
return n+1;
}
else if(m!=0 && n==0)
{
return A(m-1,1);
}
else if(m!=0 && n!=0)
{
return A(m-1,A(m,n-1));
}
}
int main()
{
int x=A(2,2);
cout<<x<<" ";
system("pause");
return 0;
}
Output :
Question 02
#include <iostream>
#include <conio.h>
using namespace std;

int Sum(int arr[], int size)


{
if (size <= 0)
{
return 0;
}
else
{
return (Sum(arr, size - 1) + arr[size - 1]);
}
}
int main()
{
int arr[] = { 1, 2, 3, 4,5,6};
int size = sizeof(arr) / sizeof(arr[0]);
int x=Sum(arr, size);
cout<<x;
system("pause");
return 0;
}

Output:
Question 03
#include <iostream>
#include <conio.h>
using namespace std;
int print(int end, int start)
{
cout<<end<<" ";
end--;
if (end== start)
{
cout<<" ";
}
else
{
return print(end,start);
}
}
int main()
{
print(10,0 );
system("pause");
return 0;
}

Output
Question 04
#include <iostream>
#include <conio.h>
using namespace std;
int print(int n, int m)
{
if(m==0)
{
return 1;
}
else if (n==m)
{
return 1;
}
else
{
return ( ((n-1)/(m)) + ((n-1)/(m-1)) );
}
}
int main()
{
int x=print(3,2 );
cout<<x<<endl;
system("pause");
return 0;
}

Output:

You might also like