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

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

View Full Document Right Arrow Icon
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 — Computer Fundamentals Midterm Examination October 27, 2009 12:20 p.m. – 1:50 p.m. Examiners: J. Anderson, T. Fairgrieve, H. Ghaderi, B. Li Exam Type A: This is a “closed book” examination; no aids are permitted. Calculator Type 4: No calculators and other electronic devices are allowed. All questions are to be answered on the examination paper. If the space provided for a question is insufFcient, you may use the last page to complete your answer. If you use the last page, please direct the marker to that page and indicate clearly on that page which question(s) you are answering there. You must use the C programming language to answer programming questions. The examination has 11 pages, including this one. Circle your lecture section ( one mark deduction if you do not correctly indicate your section): L0101 or L0102 or L0103 or L0104 or L0105 ±airgrieve Ghaderi Ghaderi Anderson Li Monday 2 PM Monday 9 AM Monday 11 AM Monday 11 AM Monday 4 PM ±ull Name: Student Number: EC± Login: MARKS 1 2 3 4 5 6 7 8 9 10 11 12 13 Total /4 /4 /4 /4 /4 /4 /8 /8 /12 /12 /12 /12 /12 /100
Background image of page 1

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

View Full DocumentRight Arrow Icon
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:
Background image of page 2
Image of page 3
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 Right Arrow Icon
Ask a homework question - tutors are online