Assignment-2
Assignment-2
Experiment - 4
a. #include <iostream>
using namespace std;
int main() {
// your code goes here
cout << "enter the nos: " << endl;
int n, m;
cin >> n >> m;
int arr[n][m];
int brr[n][m];
cout << "Enter first array: " << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> arr[i][j];
}
}
cout << "Enter secound array: " << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> brr[i][j];
}
}
cout << "Enter a for add and s for sub" << endl;
char ch;
cin >> ch;
if (ch == 'a')
{
cout << "Final array: " << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << arr[i][j] + brr[i][j] << " ";
}
cout << endl;
}
}
else
{
cout << "Final array: " << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << arr[i][j] - brr[i][j] << " ";
}
cout << endl;
}
}
b. #include <iostream>
using namespace std;
int main() {
// your code goes here
cout << "Enter the dimensions of the matrix: " << endl;
int a, b;
cin >> a >> b;
int arr[a][b];
cout << "Enter first array: " << endl;
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
{
cin >> arr[i][j];
}
}
cout << "Enter the dimensions of Secound matrix: " << endl;
int n, m;
cin >> n >> m;
int brr[n][m];
#include <iostream>
#include <vector>
int count = 0;
if (target == arr[i])
count++;
return count;
int main()
int n;
cin >> n;
vector<int> arr(n);
{
cin >> arr[i];
int target;
if (ans >= 1)
} else
return 0;
Experiment -5
#include <iostream>
class Rectangle {
private:
double length;
double breadth;
public:
Rectangle(double l, double b)
{
length = l;
breadth = b;
Rectangle()
length = 0;
breadth = 0;
void setLength(double l)
length = l;
void setBreadth(double b)
breadth = b;
return length;
return breadth;
{
return length * breadth;
cout << "Length: " << length << ", Breadth: " << breadth << endl;
};
int main()
int a,b;
cin >>a>>b;
rect.display();
return 0;