C Course 2019-2020 - Week 2
November 21, 2019
Topics
- Flow Control
- Loops
Resources
https://github.com/iztech-comsoc/c-course-2019-2020/releases/download/W2/Week.2.-.Resources.zip
Homework
Multiplication Table
Write a program that prints multiplication table.
Expected output:
1 2 3 4 5 6 7 8 9
2 4 6 8 10 12 14 16 18
3 6 9 12 15 18 21 24 27
4 8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81
Power
Calculating power is one of the base operations in mathematics.
We can calculate a power operation with a single loop, with multiply the number exponent times.
For example 2^4 = (2 * 2 * 2 *2 ) is just multiplying 2, 4 times.
Make a program that calculates the given power of given base number.
Example input/output:
Enter a base number: 5
Enter an exponent: 4
5 ^ 4 = 625
Palindrome Numbers
Lets make a good example with working a number in a different way.
An palindrome number is a number that the reverse of that number is equal to the original number.
So we need to reverse a number and check if it is equal to its reverse.
We can make it with a loop, and every step of loop, we can take the last digit of original number and add it to reversed numbers last digit.
Hint: We can use "remainder = n % 10" expression for take the last digit (Not hint for how to add it to reversed number)
Example input/output:
Enter an integer: 12321
12321 is a palindrome.