subject

Download "ADDING 1 to n" program in "COURSE MATERIALS" . Find the runtime function as a function n. Remember f count each operative statement (of course comments don't count). Also write the order ("Big O"). Show work.
#include c1
using namespace std; c2
int add(int n); c3
int main() c4
{
int n; c5
cout << "Enter a nonnegative integer: "; c6
cin >> n; c7
cout << "Sum = " << add(n); c8
system("pause"); c9
return 0; c10
}
int add(int n) c11 n
{
if(n == 0) // BASE CASE c12 n
return 0; c13
else c14 n-1
return n + add(n-1); // RECURSIVE CASE c15 n-1
}

a = sum of(c1 through c10) + c12 + c13
b = c14 + c15
d = c11
a + b(n-1) + dn = (b+d)n + a - b
linear f(n) O(n)
n + 2(n-1) + 12

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 23.06.2019 03:10
Fill in the following program so that it will correctly calculate the price of the orange juice the user is buying based on the buy one get one sale.#include //main functionint main() { int cartons; float price, total; //prompt user for input information printf("what is the cost of one container of oj in dollars? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & price); printf("how many containers are you buying? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & cartons); if ( [ select ] ["cartons / 2", "cartons % 1", "cartons % 2", "cartons % price", "cartons / price", "cartons / total"] [ select ] ["=", "==", "! =", "< =", "> =", "< "] 0) total = [ select ] ["price * cartons", "cartons * price / 2 + price", "(cartons / 2) * price", "cartons / (2.0 * price)", "(cartons / 2.0) * price + price", "((cartons / 2) * price) + price"] ; else total = ((cartons / 2) * price) + price; printf("the total cost is $%.2f.\n", total); return 0; }
Answers: 2
question
Computers and Technology, 23.06.2019 18:40
Johnson enterprises uses a computer to handle its sales invoices. lately, business has been so good that it takes an extra 3 hours per night, plus every third saturday, to keep up with the volume of sales invoices. management is considering updating its computer with a faster model that would eliminate all of the overtime processing.
Answers: 2
question
Computers and Technology, 24.06.2019 13:00
Ais a built in formula in spread spread a is any math process such as addition or subtraction. options are function and operation
Answers: 1
You know the right answer?
Download "ADDING 1 to n" program in "COURSE MATERIALS" . Find the runtime function as a function n....
Questions
question
Mathematics, 09.09.2020 14:01
Questions on the website: 13722363