In the body of the while loop
while (i < 10000000000000000) {
long long i = i*i;
cout << i ;
}
you declared the variable i
that is not initialized and has an indeterminate value and you are trying to use this indeterminate value to initialize the variable itself.
That is in this declaration
long long i = i*i;
in the initializer there is used the same declared variable i that hides the declaration of the variable with the same name that appears before the loop
Substitute the declaration for the statement
i = i*i;
But initially you should set the variable i to some value unequal to 0 for example to 10.
long long i = 10;
Otherwise the result of the expression i * i
always will be equal to 0.
Something like
#include <iostream>
using namespace std;
int main() {
long long i = 10;
while (i < 10'000'000'000'000'000) {
i = i*i;
cout << i ;
}
cout << i;
return 0;
}
Though you should be caution selecting the initial value of the variable i
because an overflow can occur in the expression i * i
and you can get an infinite loop.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…