Design a system that takes is capable of squaring its input 2D array followed by division with scalar ‘R’ For example, if the input array is A[m][n], the output should be A^2[m][n].
#include <iostream>
using namespace std;
void square(float (*array)[3], int x, int y){
for(int i = 0; i < x; i++){
for(int j = 0; j < y; j++)
array[i][j] *= array[i][j];
}
}
void divide(float (*array)[3], int x, int y, float R){
for(int i = 0; i < x; i++){
for(int j = 0; j < y; j++)
array[i][j] /= R;
}
}
int main(){
float array[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
cout<<array[i][j]<<" ";
}
cout<<endl;
}
cout<<"\nSquaring\n";
square(array, 3, 3);
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
cout<<array[i][j]<<" ";
}
cout<<endl;
}
cout<<"\nDividing\n";
divide(array, 3, 3, 5);
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
cout<<array[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
Comments
Leave a comment