August 1, 2002



CS 201 (Introduction to Computing)

Summer 2012

Sabancı University - Sample Questions and Solutions for Midterm

• Those questions do not imply any favorite subject or question type for the questions in the actual exam

• Please also review recitation questions, samples covered in the class, homeworks and the questions in the book as well

• The amount of questions here is of course much more than the actual exam.

QUESTIONS

1) Write a function that takes an integer type of parameter and returns its reciprocal. If the parameter is zero, then the function should return 0.

In the main program, first input two integer values. Then find the sum of the reciprocals of all of the numbers between these two inputs. In the main program, you have to use the reciprocal function.

#include

using namespace std;

double reciprocal(int number)

{

if(number == 0)

return 0;

else

return (1.0/number);

}

int main()

{

int start,end;

cout > start >> end;

double sum = 0;

if (start > end)

cout ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download