- Even numbers
Write a program that prints all even numbers from (including) 10 to
(including) 100. Each number should be printed on a separate line.
Name the source file: even_numbers.c
- Alphabet
Write a program that prints all lower case characters from 'a' to 'z'
on a single line without any separator. The program has to print one
character at a time using a while loop. Print a newline (\n
)
character at the end of the sequence.
Name the source file: alphabet.c
- Sum of a Special Sequence
Write a program that calculates the sum of all odd numbers greater
than or equal to 50 and less than 1110 if the numbers can be
divided by 3 without a remainder. Print the result to
stdout
.
Once you have a working solution, consider if there is a better solution.
Name the source file: special_sequence_sum.c
- Faculty Function
The faculty of an integral number is the product of all integral numbers
between 1 and that number. For example, the faculty of 5 (usually written
as 5! is 5 * 4 * 3 * 2 * 1. Write a program that
calculates the faculty of 13 (13!) and prints the result
to the terminal. Verify that your result is correct!
Name the source file: faculty.c
- Sum of Digits
For many purposes it is useful to calculate the sum of the digits of a
number. For example, the sum of the digits facilitates knowing whether or
not a number can be divided by 3.
Write a program that asks the user to input a number and calculates the sum
of its digits. The sum of the digits has to be printed to
stdout
.
A sample run of this program:
Enter a number: 123
The sum of the digits in 123 is 1 + 2 + 3 = 6.
Name the source file: digit_sum.c
- Sum of a Sequence of Numbers (more generic)
Writing a program that always computes the same output has very limited
utility. Based on your special_sequence_sum.c program
write a new program that allows users to enter the lower limit (inclusive)
and the upper limit (exclusive) of a sequence of numbers to be summed.
Users also have to be able enter a number in case they only want every
second / third / fourth / ... number to be summed up.
That number has to default to 1.
Print the result to
stdout
.
Once you have a working solution, consider if there is a better solution.
A sample run of this program:
This programs computes the sum of a sequence of numbers.
Enter the lower limit (inclusive): 123
Enter the upper limit (exclusive): 456
Only sum every nth number [default: 1 (every number)]: 100
The desired sum is 1092.
Note that 1092 is the sum of 123 + 223 + 323 + 423.
Name the source file: sequence_sum.c
-
Mathematical functions
Write a program that prints the sine and cosine of all values between 0 and
π in steps of 0.1. The last value must be π. All values
should be fixed to 2 digits after the decimal point.
Please note that trigonometric functions are available in
math.h
. For compiling programs that use
math.h
, you have to pass -lm when compiling
(ie. clang trigonometry.c -o trigonometry -lm).
A sample run of this program:
radians | sine | cosine
------------------------
0.0 | 0.00 | 1.00
0.1 | 0.10 | 1.00
0.2 | 0.20 | 0.98
[...]
3.0 | 0.14 | -0.99
3.1 | 0.04 | -1.00
3.14 | 0.00 | -1.00
Name the source file: trigonometry.c