#include "math.h"
#include "time.h"
都有什么用?
math.h是数学函数头文件可以帮助求一些运算的例如开方,取模,求绝对值等 具体包含哪些数学函数和使用方法你可以查查书的
stdlib.h 是系统函数头文件包括exit 和itoa
exit是结束程序且返回值将被忽略
原型: void exit(int retval);
#include <stdlib.h>main()
{
int i;
for(i=0;i<10;i++)
{
if(i==5) exit(0);//结束程序
else
{
clrscr();
printf(\"%d\",i);
getchar();
}
}
getchar();
return 0;
}
#include <stdlib.h>main()
{
int i=7412;
printf(\"%d\",i);
printf(\"%s\",itoa(i));//把i转换为字符串并输出
getchar();
return 0;
}
tm结构:
struct tm {
int tm_sec; /* seconds after the minute - [0,59] * /
int tm_min; /* minutes after the hour - [0,59] * /
int tm_hour; /* hours since midnight - [0,23] * /
int tm_mday; /* day of the month - [1,31] * /
int tm_mon; /* months since January - [0,11] * /
int tm_year; /* years since 1900 * /
int tm_wday; /* days since Sunday - [0,6] * /
int tm_yday; /* days since January 1 - [0,365] * /
int tm_isdst; /* daylight savings time flag * /
};
例如:
#include <time.h>main()
{
time_t now;
{
struct tm *l_time;
char string1[20];
time(&now);
l_time = localtime(&now);
strftime(string1, sizeof string1, \"%d/%b/%y\n\", l_time);
printf(\"The current date is %s\", string1);
}
}//结果为The current date is 12/Oct/06