Make your own free website on

Topic 8 - Sample Questions - Functions (6 days)


1. Write a function that will receive 3 numbers and return the smallest one.

    int small(int a,inr b,int c)


2. Write a function that will raise a base to an exponent

    int raise(int b,int e)


3. Write a function that will return the sum between 2 numbers.

   int sum(int a,int b)


4. Write a function that will return whether a number is prime or not

   bool isprime(int n)


5. Write a function that will return the appropriate letter grade that corresponds to the average of numbers sent to the function.

  char letter(int a,int b, int c)


6. int gcf(int a,int b)  // returns greatest common factor


7. int lcm(int a,int b)  // returns least common multiple


8.  bool IsOdd(int n)  // returns true if number sent to it is odd - otherwise false


9. int sumofodd(int n)

      // returns sum of odd numbers between 1 and n


10. bool positive(int n)  // returns true if number is positive


11. void printname(String na, int n)

      // prints name n times


12. void printfirst(String n)

    // prints first name of string


13. String getfirst(String n)

         // returns first name


14. void printfactors(int n)

        // print factors for an integer


15. int countvowels(apstring n)

     // returns how many vowels are in a string


16. void printreverse(String n)

       // prints name in reverse order


17. String everyotherletter(String n)

      // returns every other letter of string


18. String reversestring(String n)

    // returns reversed string


19. double avg(int a,int b,int c)   // returns the average


20. int abs(int a)  // returns absolute value of parameter


21. int sqrt(int n)  // returns integer square root of number sent to it


22. int cube(int n)  // returns cubed result of parameter