0% found this document useful (0 votes)
15 views1 page

Lab Repoet#05cpp

Uploaded by

skbhatti003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Lab Repoet#05cpp

Uploaded by

skbhatti003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;

int fic = 1;

int factorial(int n) {
if (n == 0 || n == 1) {
return fic;
} else {
fic = fic * n;
return factorial(n - 1);
}
}

int linearsum(int arr[], int n) {


if (n == 0) {
return 0;
} else {
return arr[n - 1] + linearsum(arr, n - 1);
}
}

int main() {
int num;
cout << "Enter a non-negative integer for factorial: ";
cin >> num;

cout << "Factorial of " << num << " is " << factorial(num) << endl;

int n;
cout << "Enter the number of elements in the array: ";
cin >> n;

int arr[n];
cout << "Enter the elements of the array:" << endl;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}

cout << "The sum of the array elements is: " << linearsum(arr, n) << endl;

return 0;
}

You might also like