2008年9月1日 星期一

計算兩者之間花了多少時間

code
#include <iostream>

using namespace std;

int main ()
{
  time_t start,end;
  // save input string
  char szInput [256];
 
  // count start
  time (&start);
  printf ("Please, enter your name: ");
  gets (szInput);
  // count stop
  time (&end);
  // save cost time dif = end - start
  double dif = difftime (end,start);
  printf ("Hi %s.\n", szInput);
  printf ("You have taken %.2lf seconds to type your name.\n", dif );
 
  system("pause");
}

沒有留言: