Question

c++

Convert the following for loop to a while loop:

for (int x = 50; x > 0; x-=2)

{

cout << x << " seconds to go.\n";

}

Answer #1

int x = 50; while (x > 0) { cout << x << " seconds to go.\n"; x -= 2; }

#include <iostream> using namespace std; int main() { int x = 50; while (x > 0) { cout << x << " seconds to go.\n"; x -= 2; } return 0; }

convert the while loop into for loop
x = int(input('Enter initial value: '))
count = 0 if(x<1):
print('Error')
exit()
print('Initial value is: ',x,' ',end='')
while(x!=1):
if(x%2==0):
x=x/2
else:
x=3*x+1
count+=1
if(x!=1):
rint('Next value is: ',int(x),' ',end='')
else: print('Final value ',int(x),', ',end='')
print('number of operations performed ',int(count),'
',end='')
break

(c programming)
Examine the following code:
int x = 5;
while(x = 0){
x += x;
}
while(x-- > 5){}
What is the final value of x? Does the assignment expression in
the first loop occur and if so, what value does it evaluate to?

True or False?
a. int i = 0;
while(i <= 20);
{
i = i+5;
cout << i << " ";
}
The above loop is an infinite loop.
for(int i =5; i>=1 ; i++)
{
cout << i << endl;
}
The above loop is an infinite loop.

im trying to make a program that will use a while loop to
repeatedly ask a user for a test score. Use a counter to exit the
loop when the user has entered 10 test scores. The loop is to
figure out the total of all the scores and the highest score. it
must use a while loop please explain problems in code
the bottom code is my work done but does not work.
#include <iostream>
using namespace std;
int...

(True or False) The following is an infinite loop.
for(int i = 0; i < 5; --i)
{
cout << "Haha";
}

IN C++ AS SIMPLE AS POSSIBLE ______
Re-write the given function,
printSeriesSquareFifth, to
use a while loop (instead of for).
• The function takes a single integer n as a
parameter
• The function prints a series between 1 and
that parameter, and also prints its result
• The result is calculated by summing the numbers between 1 and
n (inclusive). If a number is divisible by 5, its
square gets added to the result instead.
• The function does not...

Please find the errors of the following code
a)
int x[5];
int k = 10;
for (k = 0; k <= 5; k++)
{
x[k] = k -1;
}
b)
int x[5];
for (k = 1; k <= 5; k++)
{
cout << x[k-1] << endl;
}
c)
int x[5]={1,2,3,4,5}, y[5];
y = x;
for (k = 0; k < 5; k++)
{
cout << y[k] << endl;
}
d)
int size;
cin >> size;
int myArr[size];

Write in C++ a function int sumofdigits( int n ) which computes
and returns the sum of the digits of
n.
Use the following main function to test your code:
int main()
{
int n, sn;
cout << "Enter q to quit or an integer: ";
while ( cin >> n )
{
sn = sumofdigits(n);
cout << "sumofdigits( " << n << " ) = " <<
sn;
cout << "\nEnter q to quit or an integer: ";
}...

JAVA - take each for loop and rewrite as a while statement
a) int result = 0;
for (int i = 1; i <= 10; i++) { result = result + i;}
System.out.println(result);
b) int result = 1;
for (int i = 1; i <= 10; i++) {result = i - result;}
System.out.println(result);
c) int result = 1;
for (int i = 5; i > 0; i--) {result = result * i;}
System.out.println(result);
d) int result = 1;
for (int...

int main() {
while (1) {
float d;
scanf("%f", &d);
float x;
for (x = d; x <= d + 1000.0; x = x + 1000.0) {
}
printf("loop exited with x = %.14g\n", x);
}
return 0;
}
If you run the program, you will see. What number should
I use as an input to make this an infinite loop?

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 20 seconds ago

asked 7 minutes ago

asked 17 minutes ago

asked 28 minutes ago

asked 37 minutes ago

asked 55 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago