c语言编程,求绝对值的和与差。

2025-04-06 01:54:56
推荐回答(1个)
回答1:

#include
#include
int add(unsigned int a,unsigned int b)
{
return a+b;
}
int sub(unsigned int a,unsigned int b)
{
unsigned int t;
t=a>b?a:b;
printf("最大值是:%d\n",t);
return (t-a)==0?t-b:t-a;
}
int main(void)
{
int a,b;
printf("请输入两个数,如1 2:");
scanf("%d%d",&a,&b);
a=a<0?(-1)*a:a;
b=b<0?(-1)*b:b;
printf("两数之和是%d\n",add(a,b));
printf("两数之差是%d\n",sub(a,b));
return 0;
}