C# Write a recursive method called Power(base, exponent) that, when called, returns  base exponent . For example, Power ( 3, 4 ) = 3 * 3 * 3 * 3.  Assume that exponent is an integer greater than or equal to 1.  The recursion step should use the relationship: base exponent = base * base exponent – 1 The terminating condition occurs when exponent is equal to 1 because base 1 = base Incorporate this method into an application that enables the user to enter the base and exponent.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C#

Write a recursive method called Power(base, exponent) that, when called, returns  base exponent .

For example, Power ( 3, 4 ) = 3 * 3 * 3 * 3. 

Assume that exponent is an integer greater than or equal to 1.  The recursion step should use the relationship:

base exponent = base * base exponent – 1

The terminating condition occurs when exponent is equal to 1 because

base 1 = base

Incorporate this method into an application that enables the user to enter the base and exponent.

 

Requirements:

In the Main() method, declare three arrays of long data types:  baseNumbers, exponents, and results.  Each array should be created to hold exactly 5 members.

Using a FOR loop, populate the baseNumbers array with random integers between 1 and 50 and populate the exponents array with random integers between 1 and 10.  Use a random number generator to create these random numbers.

Using another FOR loop, call the Power method, passing it a member of the baseNumbers array and a member of the exponents array for each iteration of the loop.  Store the returned values in the results array.

The Power method should use the algorithm described above and MUST be recursive, taking two longs as arguments and returning a long data type.

Create another method called PrintArrays that takes as arguments the three arrays you created above and returns void.  The method should print a header as “Base”, “Exponent”, and “Result” with each word separated with a single tab character.  Using a FOR loop, iterate over each array using the GetUpperBound method to determine the condition for which the loop terminates.  For each iteration of the loop, print out the base, exponent, and result from each array under the appropriate column headings.  (Hint:  You may need to use one or more tabs to separate the data values to make them line up with the headers above.)

The Main() method should call the PrintArrays method, passing in the three arrays as arguments.

Your output should resemble the example below:

A file:///C:/209 C# Programming/Programming Assignments/Module 3/Assignment_3_Solution/Assignment_.
Base
26
34
18
11
11
Press the [enter] key to exit...
Exponent
6
8
Result
308915776
1785793904896
612220032
214358881
214358881
8
8
Transcribed Image Text:A file:///C:/209 C# Programming/Programming Assignments/Module 3/Assignment_3_Solution/Assignment_. Base 26 34 18 11 11 Press the [enter] key to exit... Exponent 6 8 Result 308915776 1785793904896 612220032 214358881 214358881 8 8
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education