Lee_assig24 - int n = 0 cout <<...

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 &lt;&lt; &quot;Enter the number to search: &quot; cin &gt;&gt; n int i = mySearch(Number, Quantity, n) if(i == -1) cout &lt;&lt; n &lt;&lt; &quot; was not found\n&quot; else { cout &lt;&lt; n &lt;&lt; &quot; is at the &quot; &lt;&lt; i+1 if( i == 0 ) cout&lt;&lt; &quot;st position\n&quot; else if( i == 1 ) cout&lt;&lt; &quot;nd position\n&quot; else if( i == 2 ) cout&lt;&lt; &quot;rd position\n&quot; else cout&lt;&lt; &quot;th position\n&quot; } return 0 }...
View Full Document

Ask a homework question - tutors are online