fav.cpp - #include <iostream>#include <fstream> using namespace std void isPerfect(int n int i=1 int sum=0 while(i<n if(n%i=0 sum=sum i i=i 1 if(sum=n

fav.cpp - #include <iostream>#include <fstream> using...

This preview shows page 1 - 3 out of 4 pages.

#include <iostream> #include <fstream> using namespace std; void isPerfect (int n){ int i=1; int sum=0; while(i<n){ if(n%i==0) sum=sum+i; i=i+1; } if(sum==n){ cout<<"Y\t"; } else{ cout<<"N\t"; } } bool isPrime (int m ){ int i; // add in 1 and 2, as they are exceptions. you gotta return true if m==2, and then do another check to return false if m==1 or if m%2==0 for (i=3; i<=m/2; i=i+1){ if (m%i==0){ return false; } } return true; } void isSphenic (int k){ int count=0; int prod=1; int prime; for(int i=1; i<k/2;i=i+1){ prime=isPrime(k); if(prime && k%i==0){ prod=prod*i; count=count+1; } if(prod==k && count==3){ cout<<"Y\t"; } else{ if(prod!=k && count==3){ count=2; } } } cout<<"N\t"; } void isPerfectSquare (int l){ int i=1; int r=1; while(r<l){ i = i +1 ; r = i*i; } if (r==l){ cout<<"Y\t";
Image of page 1
} else { cout<<"N\t"; } } void binary (int q){ int binNum[8]; int i=0; int r; int j=0; for(i=0; i<8;i=i+1){ binNum[i]=0; } while (q!=0){ binNum[7-j]=q%2; q=q/2; j=j+1; } for(i=1;i<8;i=i+1){ cout<<binNum[i]; } } void stars(int q){ int num=q/5; for(int i=1; i<=num; i=i+1) { cout <<"*"; } } int main(){ int fav[999]; int n; int i=0; int invalid=0; int valid= 0; int zero=0; int f; int ranges[10];
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 4 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes