Lee_assig24 - int n = 0 cout<<"Enter the number to...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 //Cheu Lee Assig 24 #include <iostream> using namespace std int mySearch(const int *Array, const int Size, const int ToSearch) { bool NotFound = true int i = 0 { if( ToSearch != Array[i]) i++ else NotFound = false } if( NotFound == false ) return i else return -1 } int main() { int Number[8] = { 1, 3, -1, 0, 5, 7, 2, 11 } int Quantity = sizeof(Number) / sizeof(int)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int n = 0 cout << "Enter the number to search: " cin >> n int i = mySearch(Number, Quantity, n) if(i == -1) cout << n << " was not found\n" else { cout << n << " is at the " << i+1 if( i == 0 ) cout<< "st position\n" else if( i == 1 ) cout<< "nd position\n" else if( i == 2 ) cout<< "rd position\n" else cout<< "th position\n" } return 0 }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online