Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Use C language to find the absolute value of a number and output it
Use C language to find the absolute value of a number and output it

The absolute value seems to be the abs function, call it directly

If you don’t call it directly, use If else

If x is greater than 0, output it directly

< p>If x is less than 0, subtract x from 0 and assign it to y before outputting

#include

#include

< p>int main()

{

int x;

scanf("%d",&x);

x= abs(x);

printf("%d",x);

return 0;

}

#include< stdio.h>

#include

int main()

{

int x;

scanf("%d",&x);

if(x>=0)

{

printf("%d", x);

}

else

{

x=0-x;}

printf( "%d",x);

return 0;

}