Write a program that uses a loop to generate, and output to the screen, the sequence of
values 1, 2.5, 6.25, 15.625, 39.0625, ..., 2.5^n
, where n ≥ 0. n=15 is input from the
keyboard.
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int n = 0;
double a = 0;
cout << "Please Enter the value of n: " << endl;
cin >> n;
for(int i = 0; i < n; i++ )
{
a = pow (2.5 , i );
cout << a <<" , ";
}
return 0;
}
Write a program that uses a loop to generate, and output to the screen, the sequence of
values 1, 2.5, 6.25, 15.625, 39.0625, ..., 2.5^n
, where n ≥ 0. n = 15 which is input from the
keyboard.
c++ loops can all be interchanged with some extra code (for example a do-while can be changed to a while if you repeat the loop body twice). You can also jump-loop using branched goto to emulate all of the loop types.
your for loop as a while might look like this
i = 0; //extra code to use other loop type
while (i++ < n)
{