EXAAAAAAM!!!!

Welcome back to my blog!

Today I’m going to show you my second partial exam of my course. It was not a very hard exam and I’m proud of my work in it.

Lets start!

The exam said that we need to write four differents codes and these are the instructions for each code:

  1.  Write a function called triangles which receives a single parameter (int) which represents the size of a triangle as explained below. The function should print a triangle using loops (for or while). The only characters printed here are ‘T’ and the new-line character. The first line is length one, the middle line is length size and the last line is length one.

    The example below is for size 6:

    tes

Here’s my code:

2016-04-15 (1)

tes1

NEEEEEXT!

2. Write a function called superpower that has two parameters of type long and returns a long which is first parameter raised to the power of the second, which is to say it returns a b So, superpower(3,4) would return 81.

long superpower(long a, long b){

}

Here’s the code:

2016-04-15 (3)

tes12

NEEEEXT!

3. NOTE: for full 5 points, use a loop (not recursion). Write a function called fibonacci which receives a long “n” and returns a long which is the value of the nth number in the fibonacci series which is: 0,1,1,2,3,5,8,13,21,34,55,89………… So, fibonacci(0) would return 0. fibonacci(5) would return 5, fibonacci(8) would return 21. Note that the first two fibonacci numbers are 0 and 1. All others are the sum of the previous two fibonacci numbers.

Here’s my code:

2016-04-15 (5).png

tes123

THE LAST ONE!!

4. . Write a function called isPalindrome which receives a string “x” and returns true if the string x is a palindrome, otherwise false.

I had problems creating this one but yet at home I complete it and here is:

 

2016-04-15 (8).png

tes1231

And that’s it! All the codes that I made are simple and I explained how to make all of this kind of codes in my past posts. I expect that you can practice with it and improve your ways to programming.

These are the codes in GitHub:

First code

Second code

Third code

Fourth code

 

Thank you for the visit and come back later to see my next posts!

 

Top image by: https://www.flickr.com/photos/helah-alaqeel/6640646799/in/photolist-b7P3Wk-9HjKri-dDtu7h-5QHFEv-4iCoMu-bXSnVN-JnKMG-dNvqb5-evAxoR-6mucbk-qNTXMy-r1ngAT-65KUCk-32opj-5HRWGj-9bh2Pa-8brkHC-qc9vKZ-49tMsB-cv7upA-cKiMr3-2U8rN-4kUULT-9UPbxp-bZGRYh-bZH2dU-8Zvusq-6mu6mg-M4xYj-8Zvup1-8Zvuqb-qaGzpj-8Zvurj-aQJJsa-9WrPyC-9QAy6T-892TU1-6oKHoy-cGjQ-4o4889-9UTUza-86fvyq-c29Eys-9yoKTF-5YF7v-71UxG-c1HTJ7-b6TpBv-q4xKFU-7wps4T

CC BY-SA 4.0 EXAAAAAAM!!!! by sercho93 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.