It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
6年前关闭。
我试图使我的“步骤”或在while循环中递增,以使我的值像N = 2、4、8、16 ...的幂基本上为2到2 ^ 20。我试图做
然后让我的代码在其中运行。但是在输出中它给了我2,4,6,8,10,12 ..没有人知道正确的方法吗?
谢谢!
6年前关闭。
我试图使我的“步骤”或在while循环中递增,以使我的值像N = 2、4、8、16 ...的幂基本上为2到2 ^ 20。我试图做
for(j=1;j<=20;j++){
m=pow(2,2*i);
MAX=pow(2,20);
INC=pow(2,i);
while(m<=MAX){
然后让我的代码在其中运行。但是在输出中它给了我2,4,6,8,10,12 ..没有人知道正确的方法吗?
谢谢!
最佳答案
您可以将m
的值设为2,并在每次迭代中将m
乘以2。作为一种优化,您可以左移乘以2来代替:
int MAX = pow(2, 20);
int m = 2;
while(m <= MAX) {
//do your work
m <<= 1;
}