C语言函数及示例代码2006-12-03 20:10函数名: abs
功 能: 求整数的绝对值
用 法: int abs(int i);
程序例:
#include
#include
main(){
int number;
printf("input a number: ");
scanf("%d",&number);
printf("number: %d absolute value: %d\n", number, abs(number));
getch();
}
函数名: getch
功 能: 从控制台无回显地取一个字符
用 法: int getch(void);
程序例:
#include
#include
main() {
char ch;
printf("Input a character:");
ch = getche();
printf("\nYou input a '%c'\n", ch);
return 0;
}
函数名: fabs
功 能: 返回浮点数的绝对值
用 法: double fabs(double x);
程序例:
#include
#include
main(){
float number = -1234.0;
printf("number: %f absolute value: %f\n",
number, fabs(number));
return 0;
}
函数名: getx
功 能: 返回当前图形位置的x坐标
用 法: int far getx(void);
程序例:
#include
#include
#include
#include
main(){
int gdriver = DETECT, gmode, errorcode;
char msg[80];
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any ke