Page 75 - C++
P. 75
(b) Write a user-defined function EXTRA_ELE(int A[ ], int B[ ], int N) in C++ (3)
to find and display the extra element in Array A. Array A contains all the
elements of array B but one more element extra. (Restriction: array
elements are not in order)
Example If the elements of Array A is 14, 21, 5, 19, 8, 4, 23, 11
and the elements of Array B is 23, 8, 19, 4, 14, 11, 5
Then output will be 21
OR
Write a user defined function Reverse(int A[],int n) which accepts an
integer array and its size as arguments(parameters) and reverse the array.
Example : if the array is 10,20,30,40,50 then reversed array is
50,40,30,20,10
Ans. void EXTRA_ELE(int A[], int B[],int N)
{
int i,j,flag=0;
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
if(A[i]==B[j])
{
flag=1;
break;
}
}
if(flag==0)
cout<<"Extra element"<<A[i];
flag=0;
}
}
OR
void Reverse( int A[ ] , int n)
{
int temp;
for(int i=0;i<n/2;i++)
{
temp=A[i];
A[i]=A[n-1-i];
A[n-1-i]=temp;
}
}
(1 Mark for correct loops)
(1 Mark for checking array elements which are equal)
( ½ Mark for display the extra element)
11