Lee_assig16a - if (n==2)

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_16 #include <iostream> #include <cmath> #include <cstdlib> using namespace std int main() { int choice, flag=0 cout.setf(ios::fixed) cout.precision(2) cout<<"What would you like to do?"<<endl cout<<"Select 1, 2, or 3: "<<endl cout<<"+----------------------------------------------+\n" cout<<"| 1. Prime Number Program |\n" cout<<"| 2. Greatest Common Factor Program |\n" cout<<"| 3. Exit |\n" cout<<"+----------------------------------------------+\n" if (choice==1){ int i, j, n cout<<"Enter a positive number and the prime numbers will generate."<<endl cin>>n if (n==1) cout<<n<<endl
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (n==2) cout&lt;&lt;1&lt;&lt;2&lt;&lt;endl if (n&gt;=3){ for (int j=n j&lt;=n j++){ for (int i=2 i&lt;=sqrt(double(n)) i++)} } if (n%i==0) flag=1 } if (flag=0) int j cout&lt;&lt;&quot;The Prime numbers are: &quot;&lt;&lt;j&lt;&lt;endl break } if (choice==2){ int x, y, factor cout &lt;&lt; &quot;This program allows calculating the GCF.\n&quot;&lt;&lt;endl cout &lt;&lt; &quot;Please enter two positive intergers.\n&quot;&lt;&lt;endl cout &lt;&lt; &quot;First interger: &quot;&lt;&lt;endl cin &gt;&gt; x cout &lt;&lt; &quot;Second interger: &quot;&lt;&lt;endl cin &gt;&gt; y factor=(y&amp;&amp;x%2||3||4||5||6||7||8||9) cout &lt;&lt; &quot;The Greatest Common Factor of &quot; &lt;&lt; x &lt;&lt; &quot; and &quot; &lt;&lt; y &lt;&lt; &quot; is &quot; &lt;&lt; factor &lt;&lt; endl } return 0...
View Full Document

Ask a homework question - tutors are online