vendredi 28 septembre 2018

Trouble with understanding function that uses complex array matters

I'm a little lost with this problem. I have a function called ComplexArray.... The function int ComplexArray(int values[], int numValues) should return ture(1) if the number in the array are a Palindrome( reads the same backwards and forwards), for eg { 1 2 1} is a planidrome hence the function will return 1 but if the array was { 1 2 1 3} then return will be 0. P.S. Im new to coding so please do inform me if what im doing is wrong.

Ive included my code below, I dont understand how to use an if statement that'll allow for the "planidrome effecr". Any help will be much appreciated. Cheers :)

#include <stdio.h>
int ComplexArray(int values[], int numValues)
int i;
int X[1000];
int Y[1000];

for(i=0;i<numValues;i++){ // storing values[i] into new array
values[i] = X[i];
}

for(i=numValues-1;i>=0;i--){
values[i] = Y[i];
}

if(X[i] == Y[i]){ // Planidrome effec? is this the correct way?
return 1;}
else{
return 0;}
}

My code wont pass the test where values[1] = {100}, when values[2] = {100, 100}, values[5] = {99, 2, 2, 2, 99} and when values[4] = {99, 2, 2, 99}.

Aucun commentaire:

Enregistrer un commentaire