# Midterm - UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Question 1 [4 Marks] Write a single C statement that declares an int type variable named dice , and initializes it to be an odd random integer between - 200 and 200 . Solution: int dice = rand() % 200 * 2 - 199; Question 2 [4 Marks] Write a single C statement that declares an int type variable named position , and initializes it to be the position of a given lower-case letter in the English alphabet. The given lower-case English letter is stored in a char type variable named c , that has already been declared and initialized. For example, the position of the letter ’a’ is 1, and the position of ’z’ is 26. Solution: int position = c - ’a’ + 1; Question 3 [4 Marks] Write a single C statement that declares a bool variable named div and assigns true to div if and only if the value stored in the int variable named i is exactly divisible by 5 or 7. Assume that variable i has been declared and initialized. Solution:
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/16/2010 for the course ECE APS105 taught by Professor Maclean during the Fall '08 term at University of Toronto- Toronto.

### Page1 / 11

Midterm - UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online