Lee_assig16

# Lee_assig16 - i break b } } if (isPrime) { cout

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

Sheet1 Page 1 //Cheu Lee Assign16 #include <iostream> using namespace std void prime_num(int) int main() { int choice cout<<"What would you like to do? choose 1, 2, or 3 :\n" cout<<"+----------------------------------------------+\n" cout<<"| 1. Prime Number Program |\n" cout<<"| 2. Greatest Common Factor Program |\n" cout<<"| 3. Exit Program |\n" cout<<"+----------------------------------------------+\n" if (choice==1) cout << "Enter a positive number and the prime numbers will generate: " int num = 0 cin >> num prime_num(num) } void prime_num( int num) { bool isPrime=true b for ( int i = 0 i <= num i++) { for ( int j = 2 j <= num j++) { { isPrime=false

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: i break b } } if (isPrime) { cout &lt;&lt;&quot;Prime:&quot;&lt;&lt; i &lt;&lt; endl c } isPrime=true i } } ___________________________ #include &lt;iostream&gt; using namespace std int factor(int a, int b) int main() Sheet1 Page 2 { int x, y cout &lt;&lt; &quot;This program allows calculating the factor\n&quot;&lt;&lt;endl cout &lt;&lt; &quot;Please enter two positive intergers\n&quot;&lt;&lt;endl cout &lt;&lt; &quot;Value 1: &quot; cin &gt;&gt; x cout &lt;&lt; &quot;Value 2: &quot; cin &gt;&gt; y cout &lt;&lt; &quot;\nThe Greatest Common factor of &quot; &lt;&lt; x &lt;&lt; &quot; and &quot; &lt;&lt; y &lt;&lt; &quot; is &quot; &lt;&lt; factor(x, y) &lt;&lt; endl return 0 } int factor(int a, int b) { while( 1 ) { a = a / b if( a == 0 ) return b b = b / a if( b == 0 ) return a } }...
View Full Document

## Lee_assig16 - i break b } } if (isPrime) { cout

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

View Full Document
Ask a homework question - tutors are online