Question

Consider the following code segment, which is intended to store the sum of all multiples of...

Consider the following code segment, which is intended to store the sum of all multiples of 10 between 10 and 100, inclusive (10 + 20 + ... + 100), in the variable total.

int x = 100;

int total = 0;

while( /*  missing code */ )

{

total = total + x;

x = x - 10;

}

Which of the following can be used as a replacement for /* missing code */ so that the code segment works as intended?

A. x < 100

B. x <= 100

C. x > 10

D. x >= 10

E. x != 10

0 0
Add a comment Improve this question Transcribed image text
Answer #1


D. x >= 10

Add a comment
Know the answer?
Add Answer to:
Consider the following code segment, which is intended to store the sum of all multiples of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following incomplete code segment, which is intended to print the sum of the digits...

    Consider the following incomplete code segment, which is intended to print the sum of the digits in num. For example, when num is 12345, the code segment should print 15, which represents the sum 1 + 2 + 3 + 4 + 5. int num = 12345; int sum = 0; /*  missing loop header */ { sum += num % 10; num /= 10; } System.out.println(sum); Which of the following should replace /* missing loop header */ so that the...

  • 31. The following code segment is syntactically correct:              int number{20};          cout << number <<...

    31. The following code segment is syntactically correct:              int number{20};          cout << number << setbase(16) << " " << number                               << setbase(10) << " " << number                                 << showpos << " " << number << endl;                 T__   F__       32. The following statement wants to determine if ‘count’ is outside the     range of 0 through 100:             if (count < 0 && count > 100)                                             T__   F__ 33. There is...

  • 5. (10%) Consider the following C code segment: int fun (int a, int b) { static...

    5. (10%) Consider the following C code segment: int fun (int a, int b) { static int count; int x, *p; x= a +b; p-malloc (sizeof (int)); a) What is the lifetime of the variable count? b) What is the scope of the variable count? c) Which part of memory is the storage allocated for x? d) What is the lifetime of the variable x? e) Which part of memory is the storage allocated for the integer pointed to by...

  • //Precondition: A is sorted in ascending order. int k = 0; while ((A [k] < x)...

    //Precondition: A is sorted in ascending order. int k = 0; while ((A [k] < x) k k (k < A. length)) k + +; returns k; Which of the following replacement for the while - loop condition would fix the code segment so that it works as intended? A. (A [k] < x) || (k < A. length) B. (A [k] < x) & & (k < = A. length) C. (A [k] < = x) & & (K...

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • please help me on 12 106 Java Concepts Advanced Placement CS Study Guide 3 12. Consider...

    please help me on 12 106 Java Concepts Advanced Placement CS Study Guide 3 12. Consider the following code segment. int count = 0; for (int x = 0; x< 3; x++) for (int y = x; y < 3; y++) for (int z - y: z < 3; 2++) count++; What is the value of count after the code segment is executed? a 81 b. 27 JOHNNNN mshe thote c. 10x d. 9 e, 6 13. Each segment of...

  • Given the following C Code segment convert it to ARM assembly. Assume the following register assignment...

    Given the following C Code segment convert it to ARM assembly. Assume the following register assignment have been made before your section of code begins. C Variable Register assignment r1 y r2 r3 r10 j r11 int x=0, y=0, z=0; int main() { for (int i = 0; i<10; i++) for (int j 0; j < 20; j++) if (i* j > 100) X++; if (i j >= 15) y++; + فہه Z = X + y; }

  • MSP430 Misc.peripherals. Consider the following C source code. What does the code segment from lines 9...

    MSP430 Misc.peripherals. Consider the following C source code. What does the code segment from lines 9 ~ 12 do? USCIA0 is configured in the UART mode. Consider the following C source code. 1. char gm1[]"MSP430"; 2. void UARTO_putdchar (char c) l 3. while (! (IFG2 & UCAOTXIFG)) UCAOTXBUF 5. while (! (IFG2 & UCAOTXIFG)) 6. UCAOTXBUF=''; 7 - 9. for (int i=0; i < 6; ¡++) { 10. ch gml [il; 11 UARTO putdchar (ch) 12. ) D. (4 points)...

  • A. What is the output of the following C++ code fragment? (all variables are of type...

    A. What is the output of the following C++ code fragment? (all variables are of type int) int count-1; int y-100; while (count 3) y=y-1 ; count+t cout << y << endl; cout<< count <<endl What is the value of x after control leaves the following while loop? (all variables are of type int) B. int x0 while (x < 20) sum- sum+x cout << sum<< endl;

  • 1 Suppose you are designing a set of classes intended to represent a solar system and...

    1 Suppose you are designing a set of classes intended to represent a solar system and the planets and comets within it. Which of the following class structures is a correct representation? public class Comet { ... } public class Planet { ... } public class SolarSystem extends Planet { ArrayList <Comet> comets; ... } public class Planet { ... } public class Comet { ... } public class SolarSystem { ArrayList <Planet> planets; ArrayList <Comet> comets; ... } public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT