Server IP : 172.16.15.8 / Your IP : 18.118.144.98 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/jcwhiley/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// // p. 186 #include <iostream> using namespace std; int sum (int n) { if (n==1) return 1; else return n + sum(n-1); } int factor (int x) { if (x==1) return 1; else return x * factor(x-1); } int main() { int s; int a; // To calculate, call the function above like so. s = sum(3); a = factor(3); cout << "Are sum(3) and factor(3) equal to 6?" << "\n"; cout << "The sum with n=3 is: " << s << "\n"; cout << "The factorial 3! equals: " << a << "\n\n"; cout << "..right?" << "\n"; return 0; }