Answer to Question #245644 in C++ for xtian

Question #245644

Write a program that will create 2 two-dimensional arrays then compares the content of each array location.. The program should create a third 2-dimensional array that displays the result of the comparison as either less than (<), greater than (>) or equal n(=).




1
Expert's answer
2021-10-03T04:01:26-0400

Source code




#include <iostream>


using namespace std;


int main()
{
    int arr1[5][5]={
                    {1,2,3,4,5},
                    {1,2,3,4,5},
                    {1,2,3,4,5},
                    {1,2,3,4,5},
                    {1,2,3,4,5}
                    };
    int arr2[5][5]={
                    {1,2,3,4,5},
                    {1,2,3,4,5},
                    {1,2,3,4,5},
                    {1,2,3,4,3},
                    {1,2,3,4,6}
                    };
    string arr3[5][5];
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            if (arr1[i][j]<arr2[i][j]){
                arr3[i][j]="less than";
            }
            else if (arr1[i][j]>arr2[i][j]){
                arr3[i][j]="greater than";
            }
            else if (arr1[i][j]==arr2[i][j]){
                arr3[i][j]="equal";
            }
        }
    }
    
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            cout<<arr3[i][j]<<"\t";
            
        }
        cout<<"\n";
        
    }
    
    return 0;
}


Output






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