assign19_dummy

# assign19_dummy - int n if(c<d n=c c=d d=n for(n=1 n%c!=...

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

Sheet1 Page 1 //Cheu LeeAssig 19 #include<iostream> #include<cmath> using namespace std void isPrime(int) int gcf(int, int) int lcm(int, int) int main () { int a, b, c, d, z { cout<<"Enter a number and the largest prime number will be calculated"<<endl cin>>z isPrime(z) //prints out function cout<<"Enter two intergers and the GCF will be calculated"<<endl cin>>a>>b cout<<"The GCF is: "<<gcf(a,b)<<endl cout<<"Enter two intergers and the LCM will be calculated"<<endl cin>>c>>d cout<<"The LCM is: "<<lcm(c,d)<<endl c } return 0 } int gcf(int a, int b){ int l, m, cf for (int i=1 i<=a for (int j=1 j<=b if(a%i==0) l=i if(b%j==0) m=j if(l==m) cf=l } } return cf } int lcm(int c, int d){

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: int n if(c<d) { n=c c=d d=n } for(n=1 n%c != 0 || n%d != 0 return n } void isPrime(int z) { Sheet1 Page 2 int c, prime if (z==1){ cout<<"The prime number is:"<<endl cout<<z<<endl } if (z==2){ cout<<"The prime numbers are:"<<endl cout<<z<<endl } if (z>=3 && z<=7){ cout<<"The prime numbers are:"<<endl for (int j=3 j<=z c=j%2 if (c!=0) } cout<<j-1<<endl c } if (z>=8){ cout<<"The prime numbers are:"<<endl for (int i=7 i<=z if (i%2!=0) if (i%3!=0) if (i%5!=0) if(i%7!=0) prime=i } cout<<prime<<endl } } Sheet1 Page 3 i++){ j++){ n++) Sheet1 Page 4 j++){ i+=2){...
View Full Document

{[ snackBarMessage ]}

### Page1 / 4

assign19_dummy - int n if(c<d n=c c=d d=n for(n=1 n%c!=...

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

View Full Document
Ask a homework question - tutors are online