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

Info icon This 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; }
Image of page 1

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

View Full Document Right 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; }
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 then what is the output expected? If they are not equivalent then show how you can
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern