ممكن مساعدة في حل هاي السؤال
Write a named compare that takes 4 parameters , 2 pointers to arrays of integers, and to integers representing the number of elements in the 2 arrays.
The function should return boolean value which is true if the arrays are equal and false otherwise.
test your function in the main using diffrent arrays and checking the value returned by the function.
notes:
return false if the 2 arrays has diffrent sizes or the arrays have diffrent elements.
use pointers to solve this problem.
وهذا حلي شوفوا لي الخلل في الاجابة ..........
#include<iostream>
using namespace std;
bool compare(int *p1, int *p2, int size1, int size2);
void main()
{
int array1[5]={6,7,8,9,3};
int array2[5]={6,7,8,9,3};
int array3[4]={5,4,3,2};
int array4[4]={5,6,3,2};
compare(array1,array2,5,5);
compare(array1,array3,5,4);
compare(array3,array4,4,4);
};
bool compare(int arr1[],int arr2[], int size1, int size2)
{ int *p1;
int *p2;
p1=arr1;
p2=arr2;
if(size1==size2)
{for(int i=0;i<size1;i++)
{ if(*p1==*p2)
{p1++;
p2++;}
else
{cout<<"arrays are not equal"<<endl;
return false;
break;}
}
{cout<<"arrays are equal!"<<endl;
return true;}
}
else
{cout<<"the size is not equal!"<<endl;
return false;}
}
بليييييييييز ابي الحل اليوم ضروري لا تطنشون