5.6

¡Supera tus tareas y exámenes ahora con Quizwiz!

Write a for loop that prints, in ascending order, all the positive integers less than 200 that are divisible by both 2 and 3, separated by spaces.

for ( int i = 1; i < 200; i++ ) { if (( i % 2 ) == 0 && ( i % 3 ) == 0 ) { cout << i << " "; } }

Given an int variable k that has already been declared , use a for loop to print a single line consisting of 97 asterisks. Use no variables other than k

for (k=1;k<=97;k++){ cout << "*"; }

Assume the int variables i and result, have been declared but not initialized. Write a for loop header -- i.e. something of the form for ( . . . )for the following loop body:result = result * i;When the loop terminates, result should hold the product of the odd numbers between 10 and 20. NOTE: just write the for loop header; do not write the loop body itself.

for( i = 11, result = 1; i < 20; i += 2 )

Given an int variable count that has already been declared, write a for loop that prints the integers 50 through 1, separated by spaces. Use no variables other than count.

for ( count = 50; count > 0; count--) { cout << count << " "; }

Assume the int variables i, lo, hi, and result have been declared and that lo and hi have been initialized. Write a for loop that adds the integers between lo and hi (inclusive), and stores the result in result. Your code should not change the values of lo and hi. Also, do not declare any additional variables -- use only i, lo, hi, and result.

for ( i = lo; i <= hi; i++) { result += i; }

Write a for loop that prints the odd integers 11 through 121 inclusive, separated by spaces.

for ( int i = 11; i <= 121; i++ ) { if ( i % 2 != 0 ) cout << i << " "; }

Given an int variable n that has already been declared and initialized to a positive value , and another int variable j that has already been declared , use a for loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j.

for(j = 0; j < n; j++) { cout << "*"; }


Conjuntos de estudio relacionados

Chapter 64 Intervertebral disc diseases

View Set

Ultimate filiform needle test 1)

View Set

(Med Surg II) Unit 1: Leadership Study Guide

View Set