need the same code using loop

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include <iostream>
  #include <cmath>
  using namespace 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;
}
Last edited on
What is your question?
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.
That... wasn't a question, sorry.

What is the actual issue with your code?
Last edited on
I need the same code using while loop.
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)
{

}
Last edited on
Topic archived. No new replies allowed.