Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the difference between a while loop and a do-while loop? Write out the d

ID: 3862781 • Letter: W

Question

What is the difference between a while loop and a do-while loop? Write out the declaration statement for the variable needed to hold the word "Mississippi". Write out the proper C++ statement(s) that does the following: When N is positive, alpha is equal to 25. When N is negative or zero, alpha is equal to 100. Write out the proper C++ statement(s) that does the following: Add all the digits from 1 to 100 and output the sum to the screen. Write out the proper C++ statement(s) that does the following: As long as R is positive, the value of R will decrease by 2 and S will be increased by one.

Explanation / Answer

A.while and do while

Syntax for while

While(condition)

{

//statements

}

While statement first check the condition if it satisfies then move into the loop and if doesnt satisfy the condition it moves to the next line after the loop.

Syntax for do...while

do

{

//statements

}while(condition)

It executes the loop of statements first and checks for the condition.

B.

Void main()

{

char word[] = "mississippi"; // stores the word

return word;

}

c.

#include<iostream.h>

#include<conio.h>

void main()

{

int n,alpha;

cout<<"Enter the N value";

cin>>n;

if(n>0)

{

alpha = 25;

cout<<"the value of alpha is "<<alpha;

}

else

{

alpha = 100;

cout<<"the value of alpha is"<<alpha;

}

}

D.

#include<iostream.h>

#include<conio.h>

void main()

{

int sum = 0;

for(int i=0;i<=100;i++)

{

sum = sum+i;

}

cout<< " the sum is "<<sum;

}

E.

#include<iostream.h>

#include<conio.h>

void main()

{

int r,s =0;

cout<<"Enter the r value";

cin>>r;

if(r>0)

{

s = s+1;

r = r-2;

cout<< " the value of r and s is "<<r<<"and"<<s;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote