correct my lab c++ 2

Anonymous
timer Asked: Apr 17th, 2017

Question description

Hello, I have a lab mate but there are some questions The answers were not correct so I want to get the correct answers, i couldn't put the code here but i put the questions

correct my lab c++ 2
untitled1.png
correct my lab c++ 2
untitled2.png
correct my lab c++ 2
untitled3.png
//********************************************************* // This program calculates factorials recursively. //********************************************************* #include using namespace std; long fib(long n); int main () { cout << "Factorial of 5 is " << fib(5) << endl; cout << "Factorial of 10 is " << fib(10) << endl; cout << "Factorial of 20 is " << fib(20) << endl; } return 0; //******************************************************** long fib(long n) { if (n == 0) return 1; else return fib (n - 1) + fib (n - 2); } // base case
//********************************************************* // This program calculates factorials recursively. //********************************************************* #include using namespace std; int f(int n); int main () { cout << "Factorial of 5 is " << f(5) << endl; cout << "Factorial of 10 is " << f(10) << endl; cout << "Factorial of 20 is " << f(20) << endl; return 0; } //******************************************************** int f(int n) { if(n <= 0) return 0; else if(n ==1) return 1; else { int a = 0; int b = 1; int result = 0; for(int i = 2; i <= n; i++) { result = a + b; a = b; b = result; } return result; } }
#include using namespace std; int power(int number, int exponent); int main () { cout << "The power of 7 exponent 3 is " << power (7,3) << endl; return 0; } int power(int number,int exponent ) { if(exponent == 0) return 1; else return number * power(number, exponent -1); }
#include iostream using namespace std; #define MAX_SIZE 100 void { print(int a, int index, int limit) if(index = limit) return; cout (%d , a[index]); index++; } print(a, index, limit); void fill(int a, int limit) { for(int i = 0; i limit; i++) a[i] = i; } int main() { int limit = 0; int A[MAX_SIZE]; do{ cout Introduce limit (between 1 and cin limit; } while (limit = 0 limit fill(A,limit); print(A,0,limit); cout endl; } return 0; MAX_SIZE); MAX_SIZE );
#include using namespace std; #define MAX_SIZE 100 int small(int *a, int index, int limit) { if (index >= limit-1) return a[limit-1]; int m = smallest(a, index+1, limit); return (a[index] < m) ? a[index] : m; } void fill(int *a, int limit) { for (int i = 0; i < limit; i++) a[i] = rand() % 1000; } int main() { int limit = 0; int A[MAX_SIZE]; do { cout << "Introduce limit (between 1 and " << MAX_SIZE << "): "; cin >> limit; cout << endl; } while (limit <= 0 || limit > MAX_SIZE); fill(A,limit); cout << " The small number between ("; for (int i = 0; i < limit; i++) cout << A[i] << " "; cout << ") is " << small(A,0,limit) << endl; return 0; }

Tutor Answer

(Top Tutor) Studypool Tutor
School: Boston College
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors