EXPERIMENT - 1
AIM: To perform addition, subtraction , multiplication and division of two input numbers.
Software used -Online C++ Compiler.
Source Code -
a) Addition of two numbers.
#include<iostream>
using namespace std;
int main() {
int first_number, second_number, sum;
cout << "Enter two integers: ";
cin >> first_number >> second_number;
// sum of two numbers in stored in variable sumOfTwoNumbers
sum = first_number + second_number;
// prints sum
cout << first_number << " + " << second_number << " = " << sum;
return 0;
b) Subtraction of two numbers:
#include<iostream>
using namespace std;
int main() {
int first_number, second_number, sub;
cout << "Enter two integers: ";
cin >> first_number >> second_number;
// sub of two numbers in stored in variable subOfTwoNumbers
sub = first_number - second_number;
// prints sub
cout << first_number << " - " << second_number << " = " << sub;
return 0; }
c) Multiplication of two numbers:
#include<iostream>
using namespace std;
int main() {
int first_number, second_number, mul;
cout << "Enter two integers: ";
cin >> first_number >> second_number;
// mul of two numbers in stored in variable mulOfTwoNumbers
mul = first_number * second_number;
// prints mul
cout << first_number << " * " << second_number << " = " << mul;
return 0; }
d) Division of two numbers:
#include <iostream>
using namespace std;
int main() {
int first_number, second_number, div;
cout << "Enter two integers: ";
cin >> first_number >> second_number;
// div of two numbers in stored in variable divOfTwoNumbers
div = first_number / second_number;
// prints div
cout << first_number << " / " << second_number << " = " << div;
return 0; }
EXPERIMENT - 2
AIM- To perform multiplication of two input Matrix.
Software Used- Online C++ Compiler.
Source Code-
#include<iostream>
using namespace std;
int main()
{
int matOne[3][3], matTwo[3][3], matThree[3][3]; int i, j, k, sum=0;
cout<<"Enter 9 Elements for First Matrix: ";
for(i=0; i<3; i++){
for(j=0; j<3; j++){
cin>>matOne[i][j];
cout<<"\nEnter 9 Elements for Second Matrix: ";
for(i=0; i<3; i++){
for(j=0; j<3; j++){
cin>>matTwo[i][j];
}
// Multiplying two matrices...
for(i=0; i<3; i++){
for(j=0; j<3; j++){
sum=0;
for(k=0; k<3; k++)
sum = sum + (matOne[i][k] * matTwo[k][j]);
matThree[i][j] = sum; }
}
cout<<"\nMultiplication Result:\n"; for(i=0; i<3; i++)
{
for(j=0; j<3; j++) cout<<matThree[i][j]<<"\t";
cout<<endl;
}
cout<<endl;
return 0; }
EXPERIMENT-3
AIM -To perform addition, subtraction and division of two input matrices.
Software Used- Online C++ Compiler
Source Code-
a) Addition of two matrices-
#include<iostream>
using namespace std;
int main()
int matOne[3][3], matTwo[3][3], matThree[3][3];
int i, j, sum=0;
cout<<"Enter 9 Elements for First Matrix: ";
for(i=0; i<3; i++){
for(j=0; j<3; j++) cin>>matOne[i][j];
}
cout<<"\nEnter 9 Elements for Second Matrix: ";
for(i=0; i<3; i++){
for(j=0; j<3; j++)
cin>>matTwo[i][j];
}
// Adding two matrices...
for(i=0; i<3; i++){
for(j=0; j<3; j++){
sum=0;
sum = sum + (matOne[i][j] + matTwo[i][j]);
matThree[i][j] = sum;
}
}
cout<<"\n Addition Result: \n";
for(i=0; i<3; i++){
for(j=0; j<3; j++){
cout<<matThree[i][j]<<"\t";
cout<<endl;
cout<<endl; return 0;
b) Subtraction of two matrices-
#include<iostream>
using namespace std;
int main()
{
int matOne[3][3], matTwo[3][3], matSub[3][3], i, j;
cout<<"Enter 9 Elements for First Matrix: ";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++){
cin>>matOne[i][j];
}
cout<<"Enter 9 Elements for Second Matrix: ";
for(i=0; i<3; i++){
for(j=0; j<3; j++) {
cin>>matTwo[i][j];
for(i=0; i<3; i++){
for(j=0; j<3; j++) {
matSub[i][j] = matOne[i][j]- matTwo[i][j]; }
cout<<"\nThe New Matrix (Subtraction Result) is:\n";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++) {cout<<matSub[i][j]<<" ";
cout<<endl;
cout<<endl;
return 0; }
c) Division of two matrices-
#include<iostream>
using namespace std;
int main()
{
int matOne[3][3], matTwo[3][3], matThree[3][3]; int i, j, sum=0;
cout<<"Enter 9 Elements for First Matrix: ";
for(i=0; i<3; i++){
for(j=0; j<3; j++) {
cin>>matOne[i][j];
}
cout<<"\n Enter 9 Elements for Second Matrix: ";
for(i=0; i<3; i++){
for(j=0; j<3; j++) {
cin>>matTwo[i][j];
}
// Division two matrices…
for(i=0; i<3; i++){
for(j=0; j<3; j++){
sum=0;
sum = sum + (matOne[i][j] / matTwo[i][j]);
matThree[i][j] = sum;}
}
cout<<"\nDivision Result:\n";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++){
cout<<matThree[i][j]<<"\t";
cout<<endl;
cout<<endl;
return 0; }