{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Problem Exercises Chapter 02

# Problem Exercises Chapter 02 - Problem Exercices Chapter 02...

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

Problem Exercices Chapter 02 1 Problem Exercises 1. Page 148: Exercise 20. Write a C++ program that inputs a series of 10 numbers, and determines and prints the largest of the numbers. #include <iostream.h> int main() { int counter = 0, number, largest; cout << "Enter the first number: "; cin >> largest; while (++counter < 10) { cout << "Enter the next number : "; cin >> number; if (number > largest) { largest = number; } } cout << "Largest is " << largest << endl; return 0; } Sample Output :

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

View Full Document
Problem Exercices Chapter 02 2 6. Page 156: Exercise 63. Write a program that uses repetition and switch structures to print the song “The Twelve Days of Christmas.” One switch structure should be used to print the day (i.e., “First,” “Second,” etc.). A separate switch structure should be used to print the remainder of each verse. #include <iostream.h> int main() { for ( int day = 1; day < 13; day++) { cout << "On the "; switch (day) { // switch for current day case 1: cout << "first"; break ; case 2: cout << "second"; break ; case 3: cout << "third"; break ; case 4: cout << "fourth"; break ; case 5: cout << "fifth"; break ; case 6: cout << "sixth"; break ; case 7: cout << "seventh"; break ; case 8: cout << "eighth"; break ;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern