CS 104 Lab 8

.pdf

School

Illinois Institute Of Technology *

*We aren’t endorsed by this school

Course

201

Subject

Computer Science

Date

Apr 3, 2024

Type

pdf

Pages

5

Uploaded by MinisterAnteaterPerson263

Report
cs104 Exercise Set 8 1. You compile your code without any syntax errors, and run your program. At some point, the code does the same thing over and over again and will not stop. This is called : a. A run-on b. An infinite loop c. A hiccup d. A code ride 2. You need to write a loop that needs to run the same code NUMLOOPS times. The most appropriate type of loop is : a. A while loop b. A forever loop c. A for loop d. A goto loop 3. You need to write a loop that needs to run the same code some number of times. You won’t know how many until you run the program. The most appropriate type of loop is : a. A while loop b. A forever loop c. A for loop d. A goto loop
4. What is the output of the following code: product = 1, k = 6; while k < 9 product = product * k; k = k + 1; end out1 = sprintf(‘k is : %d’,k); out2 = sprintf(‘product is : %d’, product ); disp(out1); disp(out2); ‘k is: 9’ ‘product is: 280’ 5. What is the output of the following code: k = 6; for k = 1: 3 out1 = sprintf(‘Hello’ ); disp(out1); end out1 = sprintf(‘Done!’ ); disp(out1); ‘Hello’ ‘Hello’ ‘Hello’ ‘Done!’ 6. What is the output of the following code: k = 6; for k = 1 : 6 out1 = sprintf(‘Hello’ );
disp(out1); end out1 = sprintf(‘Done!’ ); disp(out1); ‘Done!’ 7. What is the output of the following code: sum = 0; k = 14; for k = 1:5 sum = sum + k; end out1 = sprintf(‘ k is : %d‘,k); out2 = sprintf(‘sum is : %d’,sum); disp(out1); disp(out2); ‘k is: 14‘ ‘sum is: 126‘ 8. What is the output of the following code: sum = 0; k = 14; for k = 1:40 if mod(k,10) == 0 sum = sum + k; end end out1 = sprintf(‘ k is : %d‘,k); out2 = sprintf(‘sum is : %d’,sum); disp(out1); disp(out2);
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help