the problem is:
write the sequential search method that find the last occurance of an item
the code runs but it donot give the right answer
here is my code
Code:#include<iostream> using namespace std; int seqsearch(int seq[],int size,int key) { int i; for(i=size;i>0;i--) { if(seq[i]==key) return i; return -1; } } int main() { int i; int key; int seq[10]={0,1,2,3,4,5,6,7,8,9}; int x=seqsearch(seq,10,key); cout<<"enter the key"<<endl; cin>>key; cout<<x<<endl; return 0; }