这可能是一个愚蠢的问题,但我无法弄清楚。它与n ++和++ n之间的差异有关(我以为我理解但显然不是)。
#include <stdio.h>
#include <math.h>
long algorithmA(int n);
long algorithmB(int n);
int main(){
long A, B;
A = B = 0;
int n = 1;
while(A >= B){
A = algorithmA(n);
B = algorithmB(n);
n++;
}
printf("At n = %d, Algorithm A performs in %ld seconds & "
"Algorithm B performs in %ld seconds.", n, A, B);
}
long algorithmA(int n){
return pow(n,4) * 86400 * 4;
}
long algorithmB(int n){
return pow(3,n);
}
Run Code Online (Sandbox Code Playgroud)
在这里您可能会告诉我,我正在尝试看算法A在什么时候优于算法B。功课中的功能和时间单位是给我的。
无论如何,我一直认为在while循环结束时“ ++”的顺序无关紧要。但是,如果我使用++ n而不是n …