Exercise 1

Ask the user for 2 numbers, then divide them and show the result.


Enter the dividend: 4
Enter the divisor: 2
4 / 2 == 2

Exercise 2

Get a character from the user, and display its integer equivalent. The keyword for the character datatype is char.


Enter a character: c
'c' in decimal is 99.

Exercise 3

Get a 5-character word from the user. Convert it to the "proper" capitalization (first letter is capitalized, and the rest are lowercase).


Enter a 5-character word: hElLo
Your word is Hello.

Exercise 4

Write a program to perform modulus between two floating-point values. The modulus operator % will not work on doubles. Do not use fmod from the cmath library (although you can use it to verify your results). Do not worry about negative values or modding by 0.

Here is a hint:

For two positive integers N (numerator) and D (denominator),
N can be expressed as D*m + R.
m is some integer multiple of D.
R is the remainder of the division between N and D.
R = N - D*m
R and m are unknowns in this equation.
Find m to solve for R.


Enter the dividend: 23.4
Enter the divisor: 3.2
23.4 % 3.2 == 1

Enter the dividend: 54.7
Enter the divisor: 3.14
54.7 % 3.14 == 1.32

Exercise 5 (advanced)

Use modulus and division to print the binary value of a character.


Enter a character: c
'c' in binary is 01100011.

Hint: once you have the decimal value of a character [part 3], you can google something like "99 in binary" to double-check your results. Also, characters all have 8 bits.