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

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

View Full Document Right Arrow Icon
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; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
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; }
Background image of page 2
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
Background image of page 3

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

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

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 Right Arrow Icon
Ask a homework question - tutors are online