Quiz #2

Hello,

Welcome back to my blog. Now I’m going to share with you my second quiz of the my first period.

Instructions:

  1. Write a function called superpower that has receives two parameters (ints) and returns an integer wich is first parameter raised to the power of the second, wich 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.
  2. Write a function called stars that has one parameter of type integer and PRINTS that many stars on a single line, so if we call the function with stars(5), the function will print like this:

*****

And these are the codes:

1)

2016-02-05 (5)

In this code I used a simple function with a loop in it. The loop thanks to the counter and acumulator multiplies the given base number. The power number helps as a condition next to the counter.

Then we called the superpower function in the main function and print the result.

NOTE: be careful and write the RETURN out of the loop because if you put it in it the result only will give you the first round.

2)

2016-02-05 (6)

In the stars code we only ask the user how many stars does he/she want. The answer is the condition next the counter. The difference here is that the COUT IS IN THE LOOP thas’s why the stars will be print in the console.

– Superpower’s code

– Stars’ code

Thank you for visit my blog. See you in my next post.

Top image by: http://t.umblr.com/redirect?z=https%3A%2F%2Fimgur.com%2FsZPlGIc&t=ODdjYzRjMTcyNjdlMWNjY2U0MDkzMjlhYTcwNGVmYTE1OTc1ODBlYyxyZEhPTHpuVg%3D%3D

CC BY-SA 4.0 Quiz #2 by sercho93 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.