The Expected Output is 2000 but it stops on 1980.
Note: The Execution is started from 20 and not from 0 as int i = 1
The Code:
#include <iostream>
using namespace std;
int main() {
  const int iarraysize = 100;
  int i = 1;
  int iarray[iarraysize];
  while (i < iarraysize) {
    iarray[i] = 20 * i;
    cout << iarray[i++] << "\n";
  }
}
                Arrays start at 0, and end one before their size.
You don't need an array however.
#include <iostream>
int main()
{
    int limit = 100;
    int i = 1;
    while (i <= limit)
    {
        std::cout << (i++ * 20) << "\n";
    }
}
                        The last value of the variable i that is less than 100 is 99. So 20 * 99 is equal to 1990.
If you want to get 2000 then rewrite the loop like
int i = 0;
while (i < iarraysize) {
  iarray[i] = 20 * (i + 1);
  cout << iarray[i++] << "\n";
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With