Question

What will be the output produced from the following nested loops: sum = 0; a =...

  1. What will be the output produced from the following nested loops:
  1. sum = 0;

a = 7;

while (a<10)

{

      for (k = a; k<=10; k++)

                  sum +=k;

      a++; }

cout<< sum << endl;

  1. int x, y;

for (x = 1; x<=5; x++)

{

      cout<<x<<endl;

      for (y = 2; y <x; y++)

                  cout<< y<<endl;

}

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

a)
80

b)
1
2
3
2
4
2
3
5
2
3
4

Add a comment
Know the answer?
Add Answer to:
What will be the output produced from the following nested loops: sum = 0; a =...
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
  • What is the output from each of the following segments of C++ code? Record the output...

    What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 25; j > 16; j -= 3)        cout << setw(5) << j;     Answer: 2. int sum = 0;       for (int k = -2; k <= 2; k++)         sum = sum +...

  • What does the following nested loop structure output? count = 1; while (count <= 11) {innerCount...

    What does the following nested loop structure output? count = 1; while (count <= 11) {innerCount = 1 while (innerCount <= (12 - count)/2) {cout << " "; innerCount++;} innerCount = 1; while (innerCount = 1; while (innerCount <= count) {cout << "0"; innerCount++;} cout << endl; count++;} What does the following nested loop structure output? count = 1; while (count <= 10) {innerCount = 1; while (innerCount <= 10) {cout << setw(5) << count * innerCount; innerCount++;} cout <<...

  • 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;

  • 12. What is the output of the following C++ code? int x; int y; int *p...

    12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...

  • C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an...

    C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an initial number, followed by that number of integers. Output those integers' sum. Repeat until the initial number is O or negative. Ex: If the user enters 3 96 1 0, the output is 16 Ex: If the user enters 396125 3 0, the output is 16 Hints: Use a while loop as an outer loop. Get the user's initial number of ints before the...

  • 5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8};       ...

    5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8};        for(int i=0;i<9;i++)      a[i]=a[i+1]; for(int i=0;i<8;i++)      cout<<a[i]<<” “; cout<<endl; 6. What will be shown on the output screen after following statements are executed? char a[ ]="I have a part time job"; int c=x, i=0 while(a[i]!=’\0’){      if(a[i]==' '){           c++;           cout<<endl;      }      else           cout<<a[i];      i++; } cout<<c<<endl; 7. After following statements are executed, what are the outputs char a[ ]= "Fresno City College";        for (i...

  • What will the output be in the following? int a, b, c; a-b-0; c 5; ific<...

    What will the output be in the following? int a, b, c; a-b-0; c 5; ific< 1011 (a = = 0 &&b != 0)) 3. cout<<True"; else cout<<"False", What will the output be in the following? a. int icount; 4. do count = 0; cout<<"The count is "<cicount<<endl; while(icount<10); int count = 0; do b. cout<<"The count is “<<count<<endl; while++icount<10); c. for(int n 5; n>0; n-) cout<<n;

  • 42.To learn how nested for loops work, do a walk-through of the fol-lowing program segments and...

    42.To learn how nested for loops work, do a walk-through of the fol-lowing program segments and determine, in each case, the exact out-put. (4, 7) A) int i, j;for (i = 1; i <= 5; i++) { for (j = 1; j <= 5; j++) cout << setw(3) << i; cout << endl;} B) int i, j; for (i = 1; i <= 5; i++) { for (j = (i 1 1); j <= 5; j++) cout << setw(5) <<...

  • Suppose that the input is 0 5 6 4 9 8 -1.What is the output of the following code?   in...

    Suppose that the input is 0 5 6 4 9 8 -1.What is the output of the following code?   int num = 0;    int sum;    cin >> sum;   while (num != -1)    { cin >> num; sum = sum + 2 * static_cast<int>(sqrt(num));    } cout << "Sum = " << sum << endl;

  • 18 C++ 1. What is the output of the following program segment? int y-22: while ((y...

    18 C++ 1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is

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