Unit 05 Test - UNIT 5 TEST 1. (a) Rewrite the following...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: UNIT 5 TEST 1. (a) Rewrite the following program replacing the WHILE loop with a FOR loop int main (void) { int j=2; while(j<=12) { cout << j << endl; j+=2; } return 0; } What is the output of the program? Please turn in the complete working program. (b) Will the following piece of code work if we want to print out the word "Even" if the value of the variable iA is even, else print the word "Odd"? Why would it work or not work? How can it be fixed if it does not work? int main(void) { int iA; cout << "Enter the value of iA" << endl; cin >> iA; if(iA%2==0) cout << "Even" << endl; cout << "Odd" << endl; return 0; } Assume that the header files and other lines of code are somehow magically filled in. a) #include <iostream> using namespace std; int main (void) { for ( int j =2; j <=12; j+=2) { cout << j << endl; } return 0; } /* Output of the Program 2 4 6 8 10 12 */ b) this program will work, if the number is odd. But if the number is even then it will show number is even b) this program will work, if the number is odd....
View Full Document

This note was uploaded on 10/02/2011 for the course ME 205 taught by Professor Koen during the Spring '07 term at University of Texas.

Page1 / 5

Unit 05 Test - UNIT 5 TEST 1. (a) Rewrite the following...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online