您好,欢迎来到外链网!
当前位置:外链网 » 站长资讯 » 专业问答 » 文章详细 订阅RssFeed

c语言符号用法,c语言函数用法

来源:互联网 浏览:76次 时间:2023-04-08
浙大版PTA 习题5-1 符号函数

题目要求:本题要求实现符号函数sign(x)。

函数接口定义:

int sign( int x );

其中x是用户传入的整型参数。符号函数的定义为:若x大于0,sign(x)?=?1;若x等于0,sign(x)?=?0;否则,sign(x)?=??1。

裁判测试程序样例: #include <stdio.h>int sign( int x );int main(){ int x; scanf("%d", &x); printf("sign(%d) = %d\n", x, sign(x)); return 0;}/* 你的代码将被嵌在这里 */

运行代码:

#include <stdio.h>int sign( int x );int sign( int x ){if (x>0)return 1;else if(x==0)return 0;elsereturn -1;}int main(){ int x; scanf("%d", &x); printf("sign(%d) = %d\n", x, sign(x)); return 0;}

75240475