cs31s08mid

cs31s08mid - CS31 Introduction to Computer Science I Spring...

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

View Full Document Right Arrow Icon
Discussion 1J Notes (Week 5, May 2) TA: Brian Choi ([email protected]) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 Midterm Practice Problems Problem 1 A palindrome is a word whose reading the same in either direction. Examples include "racecar", "civic", and "level". Write a function isPalindrome that takes in a string and returns true if the string is a palindrome, false otherwise. You can assume that the string does not have any space. Problem 2 What is the result of the following code, in a brief English sentence? int mystery(int k) { int i = 0; if(k < 0) return -1; while(k > 0) { if(k%3 == 0) i++; k--; } return i; } CS31: Introduction to Computer Science I Spring 2008 Week 5, Page 1/4
Background image of page 1

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

View Full DocumentRight Arrow Icon
Problem 3 What happens if you compile and run the following code? Choose one of the following and answer the question that belongs to your choice. int k[3] = {4, 10, 16}; int j = 4; int sum = 0; { j++; sum += k[j]; } cout << sum << endl; 1. It successfully compiles and prints something.
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 05/17/2009 for the course CSE CS31 taught by Professor Smallberg during the Spring '09 term at UCLA.

Page1 / 4

cs31s08mid - CS31 Introduction to Computer Science I Spring...

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