write a c++ program to enter the elements of the matrix a[4][4] then put the product of the first and last row elements of the array a in the new generated one dimensional array b[4]; finally display the array b.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(){
int a[4][4];
int b[4];
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
cout<<"Enter value ["<<i<<"]"<<"["<<j<<"]: ";
cin>>a[i][j];
}
}
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
cout<<a[i][j]<<" ";
}
cout<<"\n";
}
//put the product of the first and last row elements of the
//array a in the new generated one dimensional array b[4];
for(int i=0;i<4;i++){
b[i]=a[0][i]*a[3][i];
}
cout<<"The product of the first and last row elements of the array\n";
for(int i=0;i<4;i++){
cout<<"Column "<<i<<" = "<<b[i]<<"\n";
}
return 0;
}
Comments
Leave a comment