The absolute value of the various problems encountered in the brush

Method a: expressed in C language comes absolute value function:

If a is an integer of : ABS ()     

#include<stdio.h>
#include<math.h>
int a=100,b;
b=abs(a);
printf("%d",b);

 

If a is a floating-point number: double type     fabs ()  

#include<stdio.h>
#include<math.h>
float a=99.9float b;
b=fabs(a);
printf("%f",b);

  

Method Two: Write a function of their own, said:

#include <stdio.h>
int abs(int t)
{
    if (t>0)
        return t;
    else
        return -t;
}
int main()
{
    int t = 0;
    scanf("%d",&t);
    printf("%d",abs(t));
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/expedition/p/11626847.html