1

*Program is in C* Write a recursive function to compute a^b for integers a and b....

Question

*Program is in C* Write a recursive function to compute a^b for integers a and b....

1, write a function to compute a for a a and b. For the recursive step 1. a recursive ab integers use the following equality a b 1 a and a 1 2. What does the following recursive function do? int mystery (int a, int b) if (b3-1) return (a) else return (a mystery (a, b 1))

*Program is in C*

Write a recursive function to compute a^b for integers a and b. For the recursive use the following equality a^b = a^b - 1 * a and a^0 = 1. What does the following recursive function do? int mystery(int a, int b) {if (b == 1) return (a); else return (a + mystery(a, b - 1));}

Answers

Herer is recursive function :

int power(int a, int b)
{
if (b != 0)
return (a*power(a, b-1));
else
return 1; // a^0 = 1
}

Sample program to test:

#include <stdio.h>
int power(int a, int b);
int main()
{
printf("Result is %d\n",power(2,4));

return 0;
}

int power(int a, int b)
{
if (b != 0)
return (a*power(a, b-1));
else
return 1; // a^0 = 1
}

Output:

Result is 16

Program2:

What does the recursive does is ?

return the sum of numbers

example if a = 2 and b = 4

answer is 8

How?

2 + 2 + 2 + 2 = 8

a will sum untill b times


Similar Solved Questions

1 answers
If you didnt know these cities were all cities of the United States, how could you tell from the temperature curves that they were all in the Northern Hemisphere
if you didnt know these cities were all cities of the United States, how could you tell from the temperature curves that they were all in the Northern Hemisphere?...
1 answers
Question 5 3 pts What is the final nuclide that results from a succession of two...
Question 5 3 pts What is the final nuclide that results from a succession of two alpha emissions, followed by three beta emissions, beginning with 238 U ? 246 230 Am 95 230 Pa 91 91 249 ES 99...
1 answers
Please Solve As soon as Solve quickly I get you thumbs up directly Thank's Abdul-Rahim Taysir...
Please Solve As soon as Solve quickly I get you thumbs up directly Thank's Abdul-Rahim Taysir 3. 60 percent of women and 40 percent of men who took a class to quit smoking remained nonsmokers for at least 1 year after completing the class. Those nonsmokers then attended a success party at the en...
1 answers
Danny reads 70% of a book in 35 minutes? How long will it take him to finish?
Danny reads 70% of a book in 35 minutes? How long will it take him to finish?...
1 answers
Wolfpack Company is a merchandising company that is preparing a budget for the month of July....
Wolfpack Company is a merchandising company that is preparing a budget for the month of July. It has provided the following information: Wolfpack Company Balance Sheet June 30 Assets Cash $ 78,400 Accounts receivable 65,800 Inventory 35,200 Buildings and equipment, net of depreciati...
1 answers
(205) Problem 5: Suppose a piano tuner stretches a steel piano wire 5.5 mm. The wire...
(205) Problem 5: Suppose a piano tuner stretches a steel piano wire 5.5 mm. The wire was originally 0.775 mm in diameter, 1.29 m long, and has a Young's modulus of 2.10x10' N/m². Randomized Variables lo = 1.29 m 1=5.5 mm d=0.775 mm Calculate the force a piano tuner applies to stretch th...
1 answers
How you think the allele frequencies are being affected by genetic drift in our simulation. Do...
How you think the allele frequencies are being affected by genetic drift in our simulation. Do you think this is speeding up or slowing down the rate of allele change? Why? Plot a graph of the H (p) allele frequency over generational time (show a minimum of three generations) showing what you would ...
1 answers
Feauto Manufacturing Corporation has a traditional costing system in which it applies manufacturing overhead to its...
Feauto Manufacturing Corporation has a traditional costing system in which it applies manufacturing overhead to its products using a predetermined overhead rate based on direct labor-hours (DLHs). The company has two products, I63E and E76I, about which it has provided the following data: I63E E76I ...
1 answers
Q2 The 10 m long simply supported beam is subjected to a uniformly distributed load w...
Q2 The 10 m long simply supported beam is subjected to a uniformly distributed load w = 10 kN/m throughout and a point load P =10 kN at the midspan of the beam, as shown in Figure Q2 (a). The cross section of this beam is depicted in Figure Q2 (b), which consists of three equal rectangular steel mem...
1 answers
A company produces two products. FC Total Fixed costs $580 VC1- variable costs from product 1...
A company produces two products. FC Total Fixed costs $580 VC1- variable costs from product 1 $920 VC2 variable costs from product 2 $805 TR1 revenue from product 1 = $900 TR2- revenues from product 2- $900 In the short run, what should the firm do? Produce neither Produce product 1 but not 2 Produc...
1 answers
1) the Davis article is a A. Quantitative B. Qualitative study 2) the Davis study is...
1) the Davis article is a A. Quantitative B. Qualitative study 2) the Davis study is a A. Nonexperimental pilot study B. Casual-comparative pilot study C. Experimental pilot study 3) select the dependent variable(s) in the Davis study • Right Hesphere cerebral vascular accidents • levels o...
1 answers
Me Saved Help Save The general ledger of Pipers Plumbing at January 1, 2021, Includes the...
me Saved Help Save The general ledger of Pipers Plumbing at January 1, 2021, Includes the following account balances: Credits Debits $ 4,000 9,000 3,000 26,000 Accounts Cash Accounts Receivable Supplies Equipment Accumulated Depreciation Accounts Payable Utilities Payable Deferred Revenue Common Sto...
1 answers
Question 4 a) Derive the Rigid Column Theory of unsteady fluid flow analysis in pipelines. 10 mar...
Q4 Question 4 a) Derive the Rigid Column Theory of unsteady fluid flow analysis in pipelines. 10 marks b) A 1.75km horizontal pipe, 0.9m in diameter, is supplied by a constant-head tank. The water level in the tank is 15 m above the discharge point of the pipe. The pipe discharges directly into t...
1 answers
Problem 4: Maze A mouse travels in a maze (shown in figure). At each discrete time-step, the mouse chooses one of the doors from the room it is curently in (uniformly at random), and moves to the cho...
Problem 4: Maze A mouse travels in a maze (shown in figure). At each discrete time-step, the mouse chooses one of the doors from the room it is curently in (uniformly at random), and moves to the chosen neighboring room. Room three has a block of cheese in it (reward for the mouse (a) Model the loca...
1 answers
Reduction of NADP+ Question 10 1 pts The majority of G3P (glyceraldehyde 3-phosphate) produced in the...
reduction of NADP+ Question 10 1 pts The majority of G3P (glyceraldehyde 3-phosphate) produced in the Calvin cycle are used to regenerate RuBP. True False No new data to save, Last checked at 3:29pm Submit...
1 answers
Question 6 of 11 Calculate the activity coefficient, y, of Ca2 when the ionic Y. Ionic Activity strength of the sol...
Question 6 of 11 Calculate the activity coefficient, y, of Ca2 when the ionic Y. Ionic Activity strength of the solution, , is 0.083 M by linear interpolation of the data in the table. strength (и, М) coefficient (YCa) 0.001 0.870 0.005 0.749 YCa+ 0.01 0.675 0.05 0.485 Calculate the acti...

-- 0.011607--