微软面试题:让任务管理器画出正弦曲线 有代码求解释~
#include <stdio.h> #include <stdlib.h>
#include <math.h>
#include <Windows.h>
const double PI = 3.1415926;
const int FREQUENCY = 360;
const int AMPLITUDE = 100;
int main()
{
printf("Sine usage of CPU\n");
double dPiece = 2*PI / FREQUENCY;
DWORD dwWork, dwTick;
while(1)
{
int i;
for( i = 0; i < FREQUENCY; i++ ) {
dwTick = GetTickCount();
dwWork =(DWORD)(AMPLITUDE * (sin(dPiece * i) + 1));
while(GetTickCount() - dwTick <= dwWork)
;
Sleep(2*AMPLITUDE - dwWork);
}
}
return 0;
}
看不懂,求解释~