输入一个整数,编程求其绝对值(不能使用库函数)

如题所述

#include<stdio.h>
void main()
{
int x;

printf("please input x: ");

scanf("%d",&x);

if(x<0) x=-x;

printf("|x|=%d",x);

}

希望满意!!!望采纳!!!如果觉得好,望赞同!!!
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-03-15
函数abs()可求绝对值,采用模板还可以通用,如下
int abs(int n){
return n<0?-n:n;
}
相似回答