Quiz 2 part 1

  1. Create a program with the following function.

Write a function called superpower that has recieves two parameters (ints) and returns an integer which is firs parameter raised to the power of the second, which is to say it returns (a**b).

There are many ways to do this, but the intent is for you to use a loop or recursion.

Here is my code, in case you might need it.

I had help from “BatmanTec”

But here is how you should do it.

Start by creating the functions you will be using: “superpower”, for this you want to declare two variables “a,b”

Later on declare 3 more variables, this will be the counter (count) , in this case (x=a) and (s, would be saving the data),  (count++, meaning that each time theres a loop count will add 1 to the count), the loop will continue to add 1 until (count!=b) then it will stop and give you the answer.

Screenshot9.1.png

Then you have to define what the variables defined in the past, just by writing “int x,a,b,cout, s;

and ask for the numbers, the one you want to raise and the one you will be raising by, finally add the function known as “superpower” and show the answer

Screenshot9.2.png

Well then you must compile it on Cygwin, and check if it works

Screenshot9.3.png

And there you have it !

 

 

CC BY-SA 4.0 Quiz 2 part 1 by canadamike17 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.