Question
please help
7.(10) a. What are the four parts of a loop? (10) b. Given the following, what will print out? sum = 1; snt = 0; do sum - sum
0 0
Add a comment Improve this question Transcribed image text
Answer #1

10 a.

Four part of loop 1. Initialization: in which we initialize the variable value 2.Continuation test: in which we test the cond

Four part of loop

1. Initialization: in which we initialize the variable value

2. Continuation test: in which we test the condition is true or false.

3. Update step: in which we increment or decrement the variable.

4. Loop body: in which we write the code which we want.

10 b.

input code:

1 #include <iostream> 2 using namespace std; 999 4 int main() 5-{ /*declare the variables*/ int sum=1,cnt=0; /*use Loop for d

output:

Sum=10cnt=12 ... Program finished with exit code Press ENTER to exit console.

code:

#include <iostream>
using namespace std;

int main()
{
/*declare the variables*/
int sum=1,cnt=0;
/*use loop for do sum*/
do{
sum=sum+cnt;
cnt=sum+2;
}while(cnt<10);
/*print sum and cnt*/
cout<<"Sum="<<sum<<"cnt="<<cnt<<endl;
return 0;
}

1 #include <iostream> 2 using namespace std; 5- int main() { /*declare the variables*/ int sum=1,cnt=0; /*use loop for do sum

10.c)

Is the above a good way to write a loop? Explain. • No it not a good way to write the loop. • You should write the loop as th

Is the above a good way to write a loop? Explain.

· No it not a good way to write the loop.

· You should write the loop as the below.

do {
    sum=sum+cnt;

     cnt=sum+2;
}
while (cnt<10);

· You should write loop according to this step.

· So program can find the condition and body part of loop quickly.

· Here we write only few line of code so we can write it in any way.

· But if we make a projects than there will be very long code.

· So it is hard to find the specific if we write in any way.

Add a comment
Know the answer?
Add Answer to:
please help 7.(10) a. What are the four parts of a loop? (10) b. Given the...
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
  • 10) b.        Given the following, what will print out?                            

    10) b.        Given the following, what will print out?                                           sum = 1;               cnt = 0;               do               {        sum = sum + cnt;                         cnt = sum + 2;                                           } while ( cnt < 10 )                                 cout << “sum = “ << sum << “ cnt = “ << cnt << endl;                 (5) b.   Is the above a good way to write a loop? Explain. (Think of parts of a loop.)

  • (C++) Given the following code, please help me answer these three parts and please explain as...

    (C++) Given the following code, please help me answer these three parts and please explain as simply as you can. 1.) How many iterations of the innermost loop? (please show calculation) 2.) What is the largest output? 3.) How many zeroes at the start? (please show/explain calculation) for (int y 0; y 〈 4; y++) for (int z 0: z 〈 5; z++) cout << x * y * z くく endl;

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • Please help - Bash Given the following while loop while Sx -le 5 ie echo "Say...

    Please help - Bash Given the following while loop while Sx -le 5 ie echo "Say Hello Sx times" x-( $x 1) done Write the above loop using a until statement to produce the same result.

  • a) Write a program that uses a while loop to print all divisors of a number...

    a) Write a program that uses a while loop to print all divisors of a number supplied by the user. The program should also print the sum of all the divisors and whether the number the user entered is a prime number or not. Note: The definition of a divisor is a number that divides another evenly (i.e., without a remainder) and the definition of a prime number is a number whose only divisors are 1 and itself. b) Implement...

  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.                                                                                                           Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop                                                                                              int cnt = 1;     do {     cnt += 3;     } while (cnt < 25);     cout << cnt; It runs ________ times    ...

  • I NEED HELP WITH ALL THREE PARTS PLEASE B A flexible loop has a radius of...

    I NEED HELP WITH ALL THREE PARTS PLEASE B A flexible loop has a radius of 10.5 cm and it is in a magnetic field of B = 0.132 T. The loop is grasped at points A and B and stretched until its area is zero. It takes 0.162 s to close the loop. What is the magnetic flux B through the loop before it is streched? 4.70x10^-3 T'm^2 Hints: What is the area of the circle? What is the...

  • matlab help 16. (5 points) Given that Vo = 10 m/s, A = 30 degrees, and...

    matlab help 16. (5 points) Given that Vo = 10 m/s, A = 30 degrees, and g = 9.81 m/s? Write a while loop (including initializations) that will print time (s) and height (m) values of a projectile from time t = 0 at increments of 0.1 s as long as the projectile is above ground (while h>-0). Use one decimal digit for time and two for height. Use the equation: h = v.1 sin( A) - gt?

  • ​​​​​​​show works please Q10 10 Points Answer both parts of this question, parts (a) and (b)....

    ​​​​​​​show works please Q10 10 Points Answer both parts of this question, parts (a) and (b). (a) Find the sum of each of the infinite geometric series, if they converges. If they do not converge write DIVERGES. (0) 67 +4 87 n=0 ละ 85 8 3 n11 7+16” n=1 10 (5)" (b) Write the number 0.317171717... as a ratio of integers.

  • For this assignment, you will apply what you learned in analyzing for, while, and do-while loops...

    For this assignment, you will apply what you learned in analyzing for, while, and do-while loops by writing these statements yourself. The Java™ program you write should do the following: Display a pyramid of asterisks onscreen (i.e., a nested for loop) Display the integers 10 to 1 in decreasing order, one number per line (i.e., a while/do-whlie loop) Add 7 until the sum becomes greater than 157, at which point the program should display both the sum and the number...

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