Just simple examples of using loops and other control structures.
Factorial (1p)¶
Write a function that calculates the factorial of given number n, where n <= 20. If n is larger than 20, the function returns -1.
Use prototype int64_t factorial(int8_t n);
. The return value is the result of the factorial operation, that is n!.
Hint: For testing, you might need to use placeholder %lld
to print out 64-bit numbers if %ld
is not enough in your architecture.
Was this task useful for learning?
Hexagonal number (1.0p)¶
Write a function that checks if the given number is a annettu luku
Hexagonal number. Function returns one
1
if true, otherwise
0
.
Use function prototype uint8_t hexago(uint32_t luku);
.
You need the header inttypes.h
.
Was this task useful for learning?