Sample-Exam

# Sample-Exam - Write a complete C program to generate and...

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

Write a complete C++ program to generate and print the famous sequence of numbers called the Fibonacci series: 1 1 2 3 5 8 13 21 34 Don’t let the results get too big with limit <= 200000. #include <iostream> using std::cout; int main() { long i, j, Sum; i = 1; j = 1; Sum = i + j; cout << i << " "<<j<<" "; while ( Sum <= 200000 ) { cout<<Sum<<" "; i = j; j = Sum; Sum = i + j; } return 0; }

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

View Full Document
Trace the following program to know its output when the input given to the program is 11. What is the expected output when n = 10? Answer: 11 *********** ********* ******* ***** *** * 10 ********** ******** ****** **** ** #include <iostream> using std:cin; using std::cout; using std::endl; int main() { int n; cin >> n; for (int i = 0; i <= n / 2; i++) { for (int j = 1; j <= i; j++) cout << “ ”; for (int j = 1; j <= n – (i * 2); j++) cout << “*”; cout << endl; } return 0; }
Consider the following two C++ Programs shown below: Decide whether or not they are equivalent when the input n is 9, if they are equivalent

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/09/2009 for the course COMPUTER S n/a taught by Professor P.j.deitel during the Spring '09 term at 東京大学.

### Page1 / 4

Sample-Exam - Write a complete C program to generate and...

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

View Full Document
Ask a homework question - tutors are online