5
5
#include<iostream>
2. int addNumbers(int n) 2. using namespace std;
3. int main() { 3. int add(int n);
4. int num; 4. int main() {
5. printf("Enter a positive integer: "); 5. int n;
6. scanf("%d", &num); 6. cout << "Enter a positive integer: ";
7. printf("Sum = %d", addNumbers(num)); 7. cin >> n;
8. return 0; 8. cout << "Sum = " << add(n);
} 9. return 0;
9. int addNumbers(int n) { }
10. if (n != 0) 10. int add(int n) {
11. return n + addNumbers(n - 1); 11. if(n != 0)
12. else 12. return n + add(n - 1);
13. return n; 13. else
} 14. return n;
}
1. #include<stdio.h> 1. #include<iostream>
2. long int multiplyNumbers(int n); 2. using namespace std;
3. int main() { 3. int factorial(int n);
4. int n; 4. int main() {
5. printf("Enter a positive integer: "); 5. int n;
6. scanf("%d",&n); 6. cout << "Enter a positive integer: ";
7. printf("Factorial of %d = %ld", n, 7. cin >> n;
multiplyNumbers(n)); 8. cout << "Factorial of " << n << " = " <<
8. return 0; factorial(n);
} 9. return 0;
9. long int multiplyNumbers(int n) { }
10. if (n>=1) 10. int factorial(int n) {
11. return n*multiplyNumbers(n-1); 11. if(n > 1)
12. else 12. return n * factorial(n - 1);
13. return 1; 13. else
} 14. return 1;
}