C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. div函数
div函数的功能是将两个整数相除, 返回商和余数,其用法为:div_t (int number, int denom);程序实例如下:
#include <stdlib.h>
#include <stdio.h>
div_t x;
int main(void)
{
x = div(10,3);
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem);
return 0;
}
2. disable函数
disable函数的功能是屏蔽中断,其用法为void disable(void);程序实例代码如下:
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X
interrupt */
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
disable();
count++;
enable();
oldhandler();
}
int main(void)
{
oldhandler = getvect(INTR);
setvect(INTR, handler);
while (count < 20)
printf("count is %d\n",count);
setvect(INTR, oldhandler);
return 0;
}
3. difftime函数
difftime函数的功能是计算两个时刻之间的时间差 其用法为:double difftime(time_t time2, time_t time1);程序实例代码如下:
#include <time.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
int main(void)
{
time_t first, second;
clrscr();
first = time(NULL);
delay(2000);
second = time(NULL);
printf("The difference is: %f \
seconds\n",difftime(second,first));
getch();
return 0;
}
4. delay函数
delay函数的功能是将程序的执行暂停一段时间(毫秒),其用法为:void delay(unsigned milliseconds);程序实例代码如下:
#include <dos.h>
int main(void)
{
sound(440);
delay(500);
nosound();
return 0;
}
转载请注明出处: 程序员之家 http://www.sunxin.org