Answer to Question #161235 in C++ for Ashes

Question #161235

. Write a C++ program to compare two arrays element wise and create third array store value 1

if equal and 0 if not equal. E.g.

int array1 = [4,5,6,4,3];

int array2 = [4,3,6,3,3];

in this case resultant array should be [1,0,1,0,1]


1
Expert's answer
2021-02-08T05:08:53-0500
#include<iostream>
using namespace std;
int main(){
    int array1[5],array2[5],comp[5];
    //arrays
array1[0]=5;
array1[1]=4;
array1[2]=6;
array1[3]=7;
array1[4]=8;
array1[5]=9;

array2[0]=5;
array2[1]=3;
array2[2]=6;
array2[3]=5;
array2[4]=8;
array1[5]=10;

for(int i=0;i<=5;++i){
    if(array1[i]==array2[i]){
    comp[i]=1;
    }else{
    comp[i]=0;
    
    }



}


for( i=0;i<=5;++i){

cout<<"array1="<<array1[i]<<"\tarray2="<<array2[i]<<"\tcompare array="<<comp[i]<<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