midtermB_spr10_answers

midtermB_spr10_answers - * EXAM B ANSWERS * 1. (20 points)...

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

View Full Document Right Arrow Icon
BBBBB 1 ***** EXAM B ANSWERS ***** 1. (20 points) int n; bool isPrime; cout << "enter a number: "; cin >> n; isPrime = true; for(int i = 2; i < n; i++) { if(n%i == 0) isPrime = false; } if(isPrime) cout << n << " is prime" << endl; else cout << n << " is not prime" << endl; 2. (15 points) a) True or False (circle one) Using = instead of == in an expression to check whether two variables are equal is an error that will not be caught by the compiler. Explain why or why not. TRUE. Using = will cause the value on the right-hand-side of = to be assigned to the value on the left-hand-side and no compile-time error occurs. b) Explain the difference between a function declaration and a function definition . The declaration tells the compiler the name, return type, and number and data types of the parameters. It is essentially the function header followed by a semi- colon placed before int main().
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Page1 / 4

midtermB_spr10_answers - * EXAM B ANSWERS * 1. (20 points)...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online