// (1) function multiPrint() void multiPrint(int n, char c) { for (int i = 1; i <= n; i++) cout << c; } // upside down triangle application int main() { for (int c = 6; c >= 1; c--) { multiPrint(c, '*'); cout << endl; } } // (2) function isPrime() bool isPrime(int n) { if (n < 2) return false; for (int d = 2; d < n; d++) if (n % d == 0) return false; return true; } int main () { for (int i = 1; i <= 100; i++) if (isPrime(i)) cout << i << " "; cout << endl; return 0; } // (3) function reverse() string reverse(int n) { if (n <= 0) return 0; string ans = ""; while (n > 0) { ans = ans + (char) ('0' + n % 10); n = n / 10; } return ans; } int main () { for (int i = 1; i <= 10; i++) { cout << "Enter a positive integer: "; int n; cin >> n; cout << "That reverses to: " << reverse(n) << endl; } return 0; } // (4) function max3() int max3(int a, int b, int c) { int ans = a; if (b > ans) ans = b; if (c > ans) ans = c; return ans; } int main() { int q1, q2, q3; cout << "Enter 3 quiz scores: "; cin >> q1 >> q2 >> q3; cout << "The max score is: " << max3(q1, q2, q3) << endl; return 0; } // (5) function quadratic() double quadratic(int a, int b, int c, double x) { return x * ((x * a) + b) + c; } // (6) function fibonacci() int fibonacci(int n) { int x = 1; int current = 1; // fibonacci number x int last = 0; // fibonacci number x - 1 int next; while (x < n) { next = current + last; x++; last = current; current = next; } return current; } int main() { int x = 1; int found = 0; while (found < 5) { if (isPrime(fibonacci(x))) { cout << fibonacci(x) << endl; found ++; } x++; } return 0; } // (7) function factorIt() void factorIt(int n) { int smallFactor = 2; while (n > 1) { while (n % smallFactor > 0) smallFactor++; cout << smallFactor << " "; n = n / smallFactor; if (n > 1) cout << "* "; } cout << endl; }