0% found this document useful (0 votes)
10 views5 pages

Lab Assignment 7

The document contains three C++ programming assignments. The first assignment involves creating a recursive function to generate Fibonacci series, the second assignment focuses on copying a 2D array, and the third assignment involves extracting a subarray from a larger array. Each assignment includes code snippets and prompts for user input.
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)
10 views5 pages

Lab Assignment 7

The document contains three C++ programming assignments. The first assignment involves creating a recursive function to generate Fibonacci series, the second assignment focuses on copying a 2D array, and the third assignment involves extracting a subarray from a larger array. Each assignment includes code snippets and prompts for user input.
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/ 5

Assignment #7

Question #1:
Write a C++ Program using recursion function call for Fibonacci series.

Code:
#include <iostream>
using namespace std;
int Fibonicci(int N);
int main() {
int Number;
cout << "Enter number: ";
cin >> Number;
cout<<"The series is: ";
for (int i = 0; i < Number; i++) {
cout << Fibonicci(i)<<" ";
}
return 0;
}
int Fibonicci(int N) {
if (N<=0) {
return 0;
}
else if (N==1) {
return 1;
}
else {
return (Fibonicci(N - 1) + Fibonicci(N - 2));
}
}

Output:

SP24-BSE-106(SAMI ULLAH) 1
Assignment #7

Question #2:
Code:
#include <iostream>
using namespace std;

const int MAX_ROW = 3;


const int MAX_COL = 5;

void Copy(const int X[][MAX_COL],int Y[][MAX_COL],int Rows);


int main() {

int X[MAX_ROW][MAX_COL];
int Y[MAX_ROW][MAX_COL];
cout << "Enter elements(of array): "<<endl;
for (int i = 0; i < MAX_ROW; i++) {
for (int j = 0; j < MAX_COL; j++) {
cin >> X[i][j];
}
}
cout << endl;
Copy(X, Y, MAX_ROW);
cout << "The Array is: "<<endl;
for (int i = 0; i < MAX_ROW; i++) {
for (int j = 0; j < MAX_COL; j++) {
cout << Y[i][j]<<" ";
}
cout << "\n";
}

return 0;
}
void Copy(const int X[][MAX_COL], int Y[][MAX_COL], int Rows) {
for (int i = 0; i < Rows; i++) {
for (int j = 0; j <MAX_COL ; j++) {
Y[i][j] = X[i][j];
}
}
}

SP24-BSE-106(SAMI ULLAH) 2
Assignment #7

Output:

Question #3:
Code:
#include <iostream>
using namespace std;

const int MAX_ROW1 = 3;


const int MAX_COL1 = 5;
const int MAX_ROW2 = 2;
const int MAX_COL2 = 2;

void SubArray2(const int X[][MAX_COL1], int Y[][MAX_COL2], int


MAX_ROW2, int MAX_COL2);
int main() {
int X[MAX_ROW1][MAX_COL1];
int Y[MAX_ROW2][MAX_COL2];
cout << "Enter elements(of array X): " << endl;
for (int i = 0; i < MAX_ROW1; i++) {

SP24-BSE-106(SAMI ULLAH) 3
Assignment #7

for (int j = 0; j < MAX_COL1; j++) {


cin >> X[i][j];
}
}
cout << endl << "Array: " << endl;
for (int i = 0; i < MAX_ROW1; i++) {
for (int j = 0; j < MAX_COL1; j++) {
cout<< X[i][j]<<" ";
}
cout << endl;
}

SubArray2(X, Y, MAX_ROW2, MAX_COL2);

cout << endl;


cout << "Resulting Subarray Y:" << endl;
for (int i = 0; i < MAX_ROW2; i++) {
for (int j = 0; j < MAX_COL2; j++) {
cout << Y[i][j] << " ";
}
cout << endl;
}

return 0;
}
void SubArray2(const int X[][MAX_COL1], int Y[][MAX_COL2], int
MAX_ROW2, int MAX_COL2) {
for (int i = 0; i < MAX_ROW2; i++) {
for (int j = 0; j < MAX_COL2; j++) {
Y[i][j] = X[i][j];
}
}
}

SP24-BSE-106(SAMI ULLAH) 4
Assignment #7

Output:

SP24-BSE-106(SAMI ULLAH) 5

You might also like