1. 1 1 2. 6 2 1 2 6 3 1 3 6 4 2 1 5 2 2 2 5 3 2 3 5 4 4 2 4 3 4 4 3. 1 3 6 10 15 4. 1 1 2 2 3 3 1 4 4 2 5 5 3 1 5. 1 1 1 1 2 1 1 2 2 1 3 1 1 3 2 1 3 3 2 2 2 2 3 2 2 3 3 3 3 3 6. 3 1 3 3 1 2 3 1 1 3 2 3 3 2 2 3 3 3 2 1 2 2 1 1 2 2 2 1 1 1 7. cout << "Enter a number (-999 to end): "; cin >> num; count = 1; sum = 0; while (num != -999 && count < 5) { sum += num; count++; cout << "Enter a number (-999 to end): "; cin >> num; } if (num != -999) sum += num; cout << "The sum is " << sum; 8. Enter a number (-999 to end): 10 Enter a number (-999 to end): 20 Enter a number (-999 to end): 30 Enter a number (-999 to end): -999 The sum is 60 9. Enter a number (-999 to end): 10 Enter a number (-999 to end): 20 Enter a number (-999 to end): 30 Enter a number (-999 to end): 40 Enter a number (-999 to end): 50 The sum is 150 10. for (i = i ; i <= 9 ; i++) { for (j = 1 ; j <= i ; j++) cout << "*"; cout << endl; } 11. for (i = 1 ; i <= 5 ; i++) { for (j = 1 ; j <= 5 - i ; j++) cout << " "; for (j = 1 ; j <= 2*i-1 ; j++) cout << "*"; cout << endl; } 12. cout << "Enter y or n: "; cin >> ans; while (ans != 'y' && ans != 'n') { cout << "Error: please enter y or n: "; cin >> ans; } 13. do { cout << "Enter y or n: "; cin >> ans; } while (ans != 'y' && ans != 'n');
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2002