c语言用自定义函数编程,c语言一些自定义函数的功能示例

本文介绍了C语言中几个常用的自定义函数,包括求整数绝对值的abs函数、无回显获取字符的getch函数、浮点数绝对值的fabs函数、图形位置坐标获取函数getx和gety,以及光标定位的gotoxy函数等。通过示例代码展示了这些函数的使用方法和功能。
摘要由CSDN通过智能技术生成

7876dd32b60e1e2ba7c312c3ca0d83b3.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值