LoginSignup
0
0

More than 5 years have passed since last update.

Cで絶対値を求める関数を実装

Last updated at Posted at 2014-10-08


#include <stdio.h>

//整数の絶対値
int absolute_integer(int n){
    return ( (n < 0) ? -n : n );
}

//小数の絶対値
double absolute_decimal(double d){
    return ( (d < 0) ? -d : d );
}


int main(){
    int a = -2014;
    double b = -10.08;

    printf("%dの絶対値は%dです\n",a,absolute_integer(a));
    printf("%fの絶対値は%fです\n",b,absolute_decimal(b));

    return 0;
}

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0