All Indices of Number
Send Feedback
Line 1 : An Integer N i.e. size of array
Line 2 : N integers which are elements of the array, separated by spaces
Line 3 : Integer x
indexes where x is present in the array (separated by space)
5
9 8 10 8 8
8
1 3 4
SOLUTION:-
#include<iostream>
using namespace std;
#include<iostream>
using namespace std;
int allIndexes(int input[],int size,int x,int output[]){
static int index=-1;
if(size==0)
{
return 0;
}
else{
if(input[0]==x)
{
output[0]=++index;
cout<<index<<" ";
allIndexes(input+1,size-1,x,output+1);
}
else{
++index;
allIndexes(input+1,size-1,x,output);
}
}
}
int main(){ int n; cin >> n; int *input = new int[n]; for(int i = 0; i < n; i++) { cin >> input[i]; } int x; cin >> x; int *output = new int[n]; int size = allIndexes(input, n, x, output); for(int i = 0; i < size; i++) { cout << output[i] << " "; } delete [] input; delete [] output; }
This is dummy text. It is not meant to be read. Accordingly, it is difficult to figure out when to end it. But then, this is dummy text. It is not meant to be read. Period.
If you have any doubts then please let me know... ConversionConversion EmoticonEmoticon