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(=).
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
Comments
Leave a comment