# ch9 test. - cout&amp;amp;lt;&amp;amp;lt;&amp;amp;quot;The...

This preview shows pages 1–6. Sign up to view the full content.

Sheet1 Page 1 Global variables = int j and int k, declared at the top above all functions Local Variables = int i as defined in the myFunction function Static Variables = int j, in the myFunction function. Constant Variables = int k, defined in the myFunction function. //The output of the code is: #include <iostream> #include <cmath> using namespace std int primeTest(int num) { { int answer=1 for(int i=2 { if(num%i == 0) answer=0 } return answer } } int main() { int primecheck=1 int numPrimes=0 int numNonPrimes=0 int numTotal=0 while(primecheck!=0) { cout<<"Please enter a positive integer to determine if it is prime or not. (Enter a '0' to exit)"<<endl cin>>primecheck

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Sheet1 Page 2 if(primecheck==0) { break } int answer = primeTest(primecheck) if(answer==0) { cout<<"The number is not prime."<<endl numNonPrimes++ }else{ cout<<"The answer is prime."<<endl numPrimes++ } } numTotal = numPrimes + numNonPrimes if(primecheck==0) {

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout&lt;&lt;&quot;The total number of primes checked was &quot;&lt;&lt;numTotal&lt;&lt;&quot; and the total number of primes found was &quot;&lt;&lt;numPrimes&lt;&lt; e } } #include &lt;iostream&gt; using namespace std void sortFunction( int a, int size ) { int min int p int i for ( p = 0 { min = p for (i = p + 1 if ( a[i] &lt; a[p] ) min = i swap ( a[p], a[min] ) } } Sheet1 Page 3 void swap ( int&amp; x, int&amp; y ) { int temp temp = x x = y y = temp } int main() { const int f = 5 int numArray[f] for(int i=0 { cout&lt;&lt;&quot;Please input an integer value for the array.&quot;&lt;&lt;endl cin&gt;&gt;numArray[i] } cout&lt;&lt;&quot;Before sorting the array.&quot;&lt;&lt;endl for(int i=0 { cout&lt;&lt;numArray[i]&lt;&lt;endl } sortFunction(numArray,5) cout&lt;&lt;&quot;After sorting the array.&quot;&lt;&lt;endl c for(int i=0 { cout&lt;&lt;numArray[i]&lt;&lt;endl } } Sheet1 Page 4 i&lt;num/2+1 ++i) Sheet1 Page 5 p &lt; size - 1 p++ ) i &lt; size i++ ) Sheet1 Page 6 i&lt;5 i++) i&lt;5 i++) i&lt;5 i++)...
View Full Document

## This note was uploaded on 04/13/2010 for the course ME me205 taught by Professor Pryor during the Spring '09 term at University of Texas-Tyler.

### Page1 / 6

ch9 test. - cout&amp;amp;lt;&amp;amp;lt;&amp;amp;quot;The...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online