[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]
========================================================================
// 1. Write a C++ program to find largest element in an array.
#include <iostream>
using namespace std;
int main()
{
int a[2],i,max;
cout << "enter the number";
for ( i = 0; i < 2; i++)
{
cin >> a[i];
}
max = a[0];
for ( i = 1; i < 2; i++)
{
if (a[i] > max)
{
max = a[i];
}
}
cout << "Largest element in the array is: " << max << endl;
return 0;
}
========================================================================
// 10. Write a C++ program that will find transpose of a matrix.
#include <iostream>
using namespace std;
int main()
{
int mat[2][2],rows,cols;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
cout << "Enter the elements of the matrix: " << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cin >> mat[i][j];
}
}
cout << "The transpose of the matrix is: " << endl;
for (int i = 0; i < cols; i++)
{
for (int j = 0; j < rows; j++)
{
, cout << mat[j][i] << " ";
}
cout << endl;
}
return 0;
}
========================================================================
// 11. Write a C++ program that will find subtraction of an matrices.
#include<iostream>
using namespace std;
class sub2d
{
int a[2][2],b[2][2],c[2][2],i,j;
public:
void get()
{
cout<<"Enter 1st array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter 2nd array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>b[i][j];
}
}
}
void disp()
{
cout<<"1st array elements are"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"2nd array elements are"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<b[i][j]<<" ";
}
, cout<<endl;
}
}
void sub()
{
cout<<"Sub of a and b array is "<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout << a[i][j]-b[i][j]<<" ";
//c[i][j]=a[i][j]-b[i][j];
}
cout<<endl;
}
}
};
int main()
{
sub2d o1;
o1.get();
o1.disp();
o1.sub();
}
========================================================================
// 12. Write a C++ program to find sum of all the diagonal elements of a
matrix.
#include <iostream>
using namespace std;
int main()
{
int a[2][2] rows, cols,diagonal_sum = 0;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
cout << "Enter the elements of the matrix: " << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cin >> a[i][j];
, }
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
if (i == j)
{
diagonal_sum += a[i][j];
}
}
}
cout << "The sum of all diagonal elements is: " << diagonal_sum << endl;
return 0;
}
========================================================================
// 13. Write a C++ program that will find multiplication of two matrices.
#include<iostream>
using namespace std;
class mul2d
{
int a[2][2],b[2][2],c[2][2],i,j;
public:
void get()
{
cout<<"Enter 1st array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter 2nd array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>b[i][j];
}
}
}
void disp()
{
cout<<"1st array elements are"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<a[i][j]<<" ";
}
========================================================================
// 1. Write a C++ program to find largest element in an array.
#include <iostream>
using namespace std;
int main()
{
int a[2],i,max;
cout << "enter the number";
for ( i = 0; i < 2; i++)
{
cin >> a[i];
}
max = a[0];
for ( i = 1; i < 2; i++)
{
if (a[i] > max)
{
max = a[i];
}
}
cout << "Largest element in the array is: " << max << endl;
return 0;
}
========================================================================
// 10. Write a C++ program that will find transpose of a matrix.
#include <iostream>
using namespace std;
int main()
{
int mat[2][2],rows,cols;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
cout << "Enter the elements of the matrix: " << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cin >> mat[i][j];
}
}
cout << "The transpose of the matrix is: " << endl;
for (int i = 0; i < cols; i++)
{
for (int j = 0; j < rows; j++)
{
, cout << mat[j][i] << " ";
}
cout << endl;
}
return 0;
}
========================================================================
// 11. Write a C++ program that will find subtraction of an matrices.
#include<iostream>
using namespace std;
class sub2d
{
int a[2][2],b[2][2],c[2][2],i,j;
public:
void get()
{
cout<<"Enter 1st array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter 2nd array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>b[i][j];
}
}
}
void disp()
{
cout<<"1st array elements are"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"2nd array elements are"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<b[i][j]<<" ";
}
, cout<<endl;
}
}
void sub()
{
cout<<"Sub of a and b array is "<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout << a[i][j]-b[i][j]<<" ";
//c[i][j]=a[i][j]-b[i][j];
}
cout<<endl;
}
}
};
int main()
{
sub2d o1;
o1.get();
o1.disp();
o1.sub();
}
========================================================================
// 12. Write a C++ program to find sum of all the diagonal elements of a
matrix.
#include <iostream>
using namespace std;
int main()
{
int a[2][2] rows, cols,diagonal_sum = 0;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
cout << "Enter the elements of the matrix: " << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cin >> a[i][j];
, }
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
if (i == j)
{
diagonal_sum += a[i][j];
}
}
}
cout << "The sum of all diagonal elements is: " << diagonal_sum << endl;
return 0;
}
========================================================================
// 13. Write a C++ program that will find multiplication of two matrices.
#include<iostream>
using namespace std;
class mul2d
{
int a[2][2],b[2][2],c[2][2],i,j;
public:
void get()
{
cout<<"Enter 1st array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter 2nd array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>b[i][j];
}
}
}
void disp()
{
cout<<"1st array elements are"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<a[i][j]<<" ";
}