Computer Science & C Programming


Exercices (2/2)

  1. Rewrite the exercice 2 from the preceding chapter by using, sub-programs definitions, and return, for or while statements
    answer
  2. A type conversion, also known as 'cast', is presented below. Using casts, propose programs to consert a numerical char, eg. '0', into a value, here 0, and its inverse function.
char c = 'X';
int i  = (int)c; // i=88=ascii code of 'X'
char d = (int)(i+1); // d='Y'
  1. Giving a letter c and a number n, define a program that shift the letter c from n in the ascii table (e.g 'a'+1 ='b', 'a'+2='c'). Nb. don't forget to use modulo %256