1.

Write a program which prints all factors of the number \(N\). The code which prints the factors should be placed inside a function. Print an additional message to the console if \(N\) is a prime number.

2.

Modify the program in such a way that it prints all prime numbers inside the range \(\{1,\ldots,\mathrm{M}\}\). Modify the function which prints factors so that it only returns information whether a number is prime or not.

3.

Write a program to see how you can use pointers and arrays:

  • declare an integer variable d,
  • initialize d with 10,
  • declare an integer pointer p,
  • initialize pointer p with the address of the variable d (p points to d),
  • print the value of d and the value which is pointed to by p (use operator *),
  • change the value of d to 20,
  • print the value of d and the value which is pointed to by p,
  • change the value pointed to by p,
  • print the value of d and the value which is pointed to by p,
  • print the address of d and the value of the pointer p (remember that the pointer stores the address, use the printf function, e.g.: printf("%p", &d);)
  • declare an array tab of integers with two elements (int tab[2];)
  • initialize elements of the array with: 333 and 444,
  • assign to the pointer p the address of the array tab,
  • fill the following table:
Address of variable Name of the variable Value of the variable
%p d %d
%p p %p
%p p[0] %d
%p t %p
%p t[0] %d
%p t[1] %d
  • find the distance (in bytes) between the addresses of the first and the second elements of the table tab