Ads

Pages

Monday, November 22, 2010

CS201 Assignment 2 Solution

using namespace std;
#include
#include
void match(int[],int[]);
main()
{
int array1[10];
int array2[10];
int arrayIndex=1;
cout << "\nPlease enter 10 integers for array1:\n" << endl;
while (arrayIndex <= 10)
{
cout << "Enter element "<cin >> array1[arrayIndex-1];
arrayIndex++;
}
arrayIndex=1;
cout << "\nPlease enter 10 integers for array2:\n" << endl;
while (arrayIndex <= 10)
{
cout << "Enter element "<cin >> array2[arrayIndex-1];
arrayIndex++;
}
match(array1,array2);
getche();
}
void match ( int Array1[], int Array2[])
{
int arrayMatch[10];
int arrayMatchIndex=0;
int i;
int loopRuns=0;
for ( i = 0 ; i <=9 ; i ++)
{
if (Array1[i] == Array2[i])
{
arrayMatch[arrayMatchIndex]=i;
loopRuns++;
arrayMatchIndex++;
}
}
if (loopRuns==10 )
{
cout << "\nBoth arrays are identical\n" << endl;
}
else if (loopRuns==0 )
{
cout << "\nNo element is same in both arrays\n" << endl;
}
else
{
cout << "\nBoth arrays have same elements on:\n" << endl;
for ( i = 0 ; i {
cout << "Index "<}
}
}

No comments:

Post a Comment