Question

A) (C#) Write a function integerPower(base, exponent) that returns the value of                             &nbsp

  1. A) (C#) Write a function integerPower(base, exponent) that returns the value of

                                        base exponent

For example, integerPower( 3, 4 ) = 3 * 3 * 3 * 3. Assume that exponent is a positive, nonzero integer and that base is an integer. The function integerPower should use for or while to control the calculation. Do not use built-in functions.

B) Write a C# console program that calls the function in A) to calculate and display the value of

1+2+4+8+…+210.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
using System;

public class IntegerPower
{
    
    public static int integerPower(int b, int exponent)
    {
        if (exponent == 0)
            return 1;

        return b * integerPower(b, exponent - 1);
    }
    
    public static void Main(string[] args)
    {
        int total = 0;
        for (int i = 0; i <= 10; i++)
        {
            total += integerPower(2, i);
        }

        Console.WriteLine(total);
    }
}

Add a comment
Know the answer?
Add Answer to:
A) (C#) Write a function integerPower(base, exponent) that returns the value of                             &nbsp
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT