fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5.  
  6. int seqsearch(int n, int* S, int x){
  7. int location = 0;
  8. while(location <= n && S[location]!=x){
  9. location++;
  10. if(S[location]==x){
  11. return location;
  12. break;
  13. }
  14. }
  15. if(location > n){
  16. location = 0;
  17. }
  18. return location;
  19. }
  20.  
  21.  
  22. int main(){
  23. int S[]={1,2,3,4,5,6,7,8,9,10};
  24. printf("%d\n",seqsearch(10, S, 5));
  25.  
  26.  
  27. }
  28.  
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
4