比率について
Posted: 2008年9月03日(水) 19:06
Aを3秒表示させ、その後Bを7秒表示させ、それを繰り返すプログラムを書きたいのですが
3:7に分けるにはどうしたら良いのですか?
3:7に分けるにはどうしたら良いのですか?
#include <stdio.h> #include <time.h> int main() { clock_t t; setbuf(stdout, NULL); for (;;) { fputs("\rA", stdout); t = clock(); while ((clock() - t) / CLOCKS_PER_SEC < 3) ; fputs("\rB", stdout); t = clock(); while ((clock() - t) / CLOCKS_PER_SEC < 7) ; } return 0; }で大丈夫かと思います。
/*************************************** * * * PCを起動してから10秒未満の時と * * 49.7日起動させている時の動作は * * 動作は良く分からない。 * * * * * ***************************************/ #include<stdio.h> #include<windows.h> int main(){ DWORD dwCount=GetTickCount()-10000; while(1){ while(GetTickCount()-dwCount<7000); //7秒の計測 dwCount=GetTickCount(); printf("A\r"); Sleep(2500); //2.5秒眠らす while(GetTickCount()-dwCount<3000); //3秒の計測 dwCount=GetTickCount(); printf("B\r"); Sleep(6500); //6.5秒眠らす } return 0; }