1) Primes and numeral systems
a) Prime factorization of the number
https://en.wikipedia.org/wiki/Prime_number#Unique_factorization
https://pl.wikipedia.org/wiki/Czynnik_pierwszy
Ex 1) Write a program which will do the prime factorization of the number.
Exemplary flow chart can be found at ./primes.gif
b) Binary and other numeral systems
https://en.wikipedia.org/wiki/List_of_numeral_systems
https://en.wikipedia.org/wiki/Binary_code
https://en.wikipedia.org/wiki/Binary_number#Conversion_to_and_from_other_numeral_systems
https://en.wikipedia.org/wiki/Hexadecimal
https://en.wikipedia.org/wiki/Octal
Additionally, see https://www.mimuw.edu.pl/~zawado/WI/WyklWI-C-sem1.pdf (page 53)
Ex 2) Write a program with two functions (decimal2binary and binary2decimal).
Ex 3) Write a generic function which takes three parameters:
i. the number to convert
ii. the numeric system of the input
iii. the numeric system of the output (the one to which you want to convert the number)
Thus,
decimal2binary(10) returns 1010
binary2decimal(11111) returns 31
and
base2base(10, 10, 2) returns ...
base2base(11111, 2, 10) returns ...
ps. obviously you are not allowed to use external libraries with build-in functions for the conversion
Moreover, limit the function to work for base 2 to base 16.
Thus, the aphabet is up to:
char base_digits[16] =
{'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
If you are not able to provide fully generic function, you can start from semi-generic solution e.g. decimal2base which will take decimal number and convert it to desired coding e.g.
decimal2base(10, 2) returns 1010
Then, you can do other direction base2decimal function.
Finaly, you can merge decimal2base and base2decimal into one: base2base
Actually, this kind of solving of the tasks is fairly common in the informatics and it is called "divide and conquere" (you split the hard task into the simple parts which can be solved easy(easier).
Homework:
Send NameSurnameLab7.tar.gz with c code and pdf file containg the pseudocode of the programs for Ex 1-3 to lukaskoz@mimuw.edu.pl
=====================================================================================
Kolokwium
https://www.mimuw.edu.pl/~zawado/WI/ZaliczenieJ2018.pdf
The "Kolokwium" will be at 10.12.18 during the lecture (thus everything will be done without the computers, just a piece of paper and a pen).
There will be three exercises to do: in the first two the student will be asked to write a function which will solve the problem. The third exercise will be theoretical (covered by the lecture).
The possible problems for codin are:
- reading from the file, making some operation on the text from file (e.g. counting words starting from 'b', counting number of lines, etc.)
- reading the file with numbers and doing some operation on them (e.g. sorting, finding max n elements, writing a number as a product of prime numbers (prime factorization of the number)
It is expected that the sutdent will be able to write the pseudocode and/or the C code for the task.
Some intro to C programming: https://www.mimuw.edu.pl/~zawado/WI/Jezyk_C.pdf