Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method called logicAnd that accepts as parameters two arrays of integer

ID: 3781739 • Letter: W

Question

Write a method called logicAnd that accepts as parameters two arrays of integer (A and B) and returns another array of integer (C). C[i] = 1 if B[i] divides A[i], otherwise C[i]=0. Write a test program (main) to declare and initialize two integer arrays of size entered by the user, invoke the method logicAnd, then display the array result. The program put the three arrays (A, B and C) in a 2-D array M as follow. Sample Run: Enter the size of the array: 5 Enter 5 numbers for A: 12 20 4 30 17 Enter 5 numbers for B: 3 6 24 15 9 The results: A 12 20 4 30 17

B 3 6 24 15 9

C 1 0 0 1 0

M 12 20 4 30 17

3 6 24 15 9

1 0 0 1 0

Explanation / Answer

//the code will be something like this:

#include <iostream>
using namespace std;
int n;       //size of the array
int c[100];   //result array

void logicAnd(int a[],int b[]);
int main()
{
   // your code goes here
  
   cout<<"Enter the size of the array ";
   cin>>n;
   int a[n], b[n];
   cout<<"Enter "<<n<<" numbers of array A:";
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   }
   cout<<"Enter "<<n<<" numbers of array B:";
   for(int i=0;i<n;i++)
   {
       cin>>b[i];
   }
   logicAnd(a,b);
   //2-d array
   int m[3][n];
   for(int i=0;i<3;i++)
   {
       for(int j=0;j<n;j++)
       {
           if(i==0)
           {
               m[0][j]=a[j];
           }
           else if(i==1)
           {
               m[1][j]=b[j];
           }
           else if(i==2)
           {
               m[2][j]=c[j];
           }
       }
   }//end of outer for loop
  
   //displaying result
   cout<<"A ";
   for(int i=0;i<n;i++)
       cout<<a[i]<<" ";
   cout<<endl;
  
   cout<<"B ";
   for(int i=0;i<n;i++)
       cout<<b[i]<<" ";
   cout<<endl;
  
   cout<<"C ";
   for(int i=0;i<n;i++)
       cout<<c[i]<<" ";
   cout<<endl;
  
   cout<<"M ";
   for(int i=0;i<3;i++)
   {
       for(int j=0;j<n;j++)
           cout<<m[i][j]<<" ";
       cout<<endl;
   }
  
  
  
   return 0;
}//end of main function

void logicAnd(int a[],int b[])
{
   for(int i=0;i<n;i++)
   {
       if(a[i]%b[i]==0)
           c[i]=1;
       else
           c[i]=0;
   }
}

//Input:

5
12 20 4 30 17
3 6 24 15 9

//output

Enter the size of the array Enter 5 numbers of array A:Enter 5 numbers of array B:A 12 20 4 30 17
B 3 6 24 15 9
C 1 0 0 1 0
M 12 20 4 30 17
3 6 24 15 9
1 0 0 1 0

Note:

In case of any difficulty please look at the following url

http://ideone.com/MKECdI

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote