2023年2月7日星期二

C abs()

abs() — Calculate Integer Absolute Value

IBM 說明

The abs() function returns the absolute value of an integer argument n.

我的理解:此函式會將輸入的整數取決對值後回傳

程式碼

  1. #include <string.h>
  2. #include <stdio.h>
  3. int main(void)
  4. {
  5. int number_in = -123;
  6. int number_out;
  7. number_out = abs(number_in);
  8. printf("number_in:%d,number_out:%d\n", number_in,number_out);
  9. }

執行結果


參考資料

https://www.ibm.com/docs/en/i/7.4?topic=files-stdlibh#stdlib

沒有留言:

發佈留言

打賞按讚