当前位置:网站首页>On absolute value function in C language

On absolute value function in C language

2022-06-12 09:05:00 Record dada I

Make a note of C Absolute value usage in language

First : The header file #include<math.h> Or is it #include<stdlib.h>

One :

about plastic Of ( namely int type ) use abs();
eg:

// I just type in the subject , Show me how to use it 
 The first one is : assignment 
int a=-10;
int b;
b=abs(a);
// When we are calculating  
 The second kind : operation 
int a=10,int b=-20;
if(a>abs(b))//
{
    
}

Two :

about floating-point That is to say (double perhaps float) use fabs()

// I just type in the subject , Show me how to use it 
// assignment 
double a=-20.5;
double b;
b= fabs(a);

// operation 
double a=10.25,b=-10.5;
if(fabs(a)>fabs(b))
{
    
}

3、 ... and :

about Long plastic surgery Of ( namely long int type ) use labs();
eg:

// I just type in the subject , Show me how to use it 
 The first one is : assignment 
long int a=-10;
long int b;
b=labs(a);
// When we are calculating  
 The second kind : operation 
long int a=,long int b=;
if(labs(a)>labs(b))
{
    
}

notes :

1. When we use these absolute value functions , Be sure to pay attention to type definitions , Be sure to pay attention to the same type , Otherwise, it is easy to swallow the number after the decimal point .
2. Call the function to add the header file , As for the function of header file , Novice can search , Easy to understand the principle .
3.long int This type of long term , In the process of our study, we use less , A lot of math can be thrown into an array in the end .
There was a lot to say , Want to finish one piece , As a result, the thought was broken after writing , When you think about it, you should add .
You are welcome to comment if you have your own opinions , Learning together , Common progress .

原网站

版权声明
本文为[Record dada I]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010531527492.html