Array C++ Passing Dynamic Arrays to a function

c-language

(Debabrata Ponda) #1

Sumita is playing with a Array A of size N . she wants to make all the values of A to be equal. she can multiply any value any number of times by X, Y and Z. Your task is to tell her whether she can do it or not. Print " She can " if she can do it else print " She can’t" without “”
Input

2
2 2 2 2
2 4
3 2 3 2
2 6 7
Expected Correct Output

She can
She can’t

#include"pch.h"
#include
using namespace std;
int multiply(int* arr, int number)
{
int count = 0;
arr[0] = number * arr[0];
if (arr[0] == arr[1])
{
count = 1;
}
else { count = -1; }
return count;
}

int main()
{
int n, size, x, y, z, count = 0, resx, resy, resz;
cout << “Enter the number of times you want to play this game”;
cin >> n;
for (int i = 0; i < n; i++)
{
cout << “\n Enter the size of array and the values of X,Y and Z”;
cin >> size >> x >> y >> z;
int* array = new int[size];
for (int j = 0; j < size; j++)
{
cin >> array[size];
}
resx = multiply(array, x);
resy = multiply(array, y);
resz = multiply(array, z);
if ((resx==1) && (resx == resy) && (resx == resz))
{
cout << “She can” << endl;
}
else
{
cout << “She can’t” << endl;
}

	}
return 0;

}

I am getting wrong output. I am getting memory address of array in multiply function. Can someone please help me out?