C language beginner level

profilechoks
ASSG2.docx

Task 1: 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 base is an integer. Function integerPower should use for to control the calculation. Do not use any math library functions.

Paste your program code in the box below

Task 2: Write statements that assign random integers to the variable n in the following ranges:

a) 1 ≤n ≤100

b) –1 ≤n ≤1

c) –3 ≤n ≤11

For each of the following sets of integers, write a single statement that will print a number at random from the set.

a) 2,4,6,8,10.

b) 3,5,7,9,11.

c)  6, 10, 14, 18, 22.

Task 3: Write a function that displays a solid square of asterisks whose side is specified in integer parameter side. For example, if side is 4, the function displays:

Table  Description automatically generated with medium confidence

Paste your program code in the box below

Task 4: An integer is said to be prime if it’s divisible by only 1 and itself.

For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not.

Write a function that determines if a number is prime.

Paste your program code in the box below

Task 5: We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Write a recursive function (no loops or multiplication) returns the total number of blocks in such a triangle with the given number of rows.

Examples:

triangle(0) → 0 triangle(1) → 1 triangle(2) → 3

Paste your program code in the box below