Answer to Question #215115 in C++ for bila

Question #215115

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].



1
Expert's answer
2021-07-08T15:52:32-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS