Number /
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
以下の数学関数を言語の標準的な関数またはメソッドで計算
※言語仕様が異なるため表示結果は完全には一致しない(結果はC++の場合)
$ ./test sin(60) = 0.866025 cos(60) = 0.5 tan(60) = 1.73205 exp(100) = 2.68812e+43 log10(100) = 2 5 ^ 3 = 125 root 5 = 2.23607 |-5| = 5 $
#include <stdio.h>
#include <math.h>
/* ラジアンを求めるマクロ */
#define RAD(x) x * M_PI / 180
int main()
{
/* 正弦 余弦 正接 */
printf("sin(60) = %f\n", sin(RAD(60)));
printf("cos(60) = %f\n", cos(RAD(60)));
printf("tan(60) = %f\n", tan(RAD(60)));
/* 指数 対数 */
printf("exp(100) = %f\n", exp(100));
printf("log10(100) = %f\n", log10(100));
/* べき乗 平方根 絶対値 */
printf("5 ^ 3 = %f\n", pow(5, 3));
printf("root 5 = %f\n", sqrt(5));
printf("|-5| = %f\n", fabs(-5));
return 0;
}
#include <iostream>
#include <cmath>
// ラジアンを求めるインライン関数
inline double RAD(double degree)
{
return degree * M_PI / 180;
}
int main()
{
// 正弦 余弦 正接
std::cout << "sin(60) = " << sin(RAD(60)) << std::endl;
std::cout << "cos(60) = " << cos(RAD(60)) << std::endl;
std::cout << "tan(60) = " << tan(RAD(60)) << std::endl;
// 指数 対数
std::cout << "exp(100) = " << exp(100) << std::endl;
std::cout << "log10(100) = " << log10(100) << std::endl;
// べき乗 平方根 絶対値
std::cout << "5 ^ 3 = " << pow(5, 3) << std::endl;
std::cout << "root 5 = " << sqrt(5) << std::endl;
std::cout << "|-5| = " << fabs(-5) << std::endl;
return 0;
}
class Main {
public static void main(String[] args) {
// 正弦 余弦 正接
System.out.println("sin(60) = " + Math.sin(Math.toRadians(60)));
System.out.println("cos(60) = " + Math.cos(Math.toRadians(60)));
System.out.println("tan(60) = " + Math.tan(Math.toRadians(60)));
// 指数 対数
System.out.println("exp(100) = " + Math.exp(100));
System.out.println("log10(100) = " + Math.log(100) / Math.log(10));
// べき乗 平方根 絶対値
System.out.println("5 ^ 3 = " + Math.pow(5, 3));
System.out.println("root 5 = " + Math.sqrt(5));
System.out.println("|-5| = " + Math.abs(-5));
}
}
# ラジアンを求める関数
sub rad {
return shift() * 3.141592653589 / 180
}
# 正弦 余弦 正接
printf("sin(60) = %f\n", sin(rad 60));
printf("cos(60) = %f\n", cos(rad 60));
printf("tan(60) = %f\n", sin(rad 60) / cos(rad 60));
# 指数 対数
printf("exp(100) = %f\n", exp(100));
printf("log10(100) = %f\n", log(100) / log(10));
# べき乗 平方根 絶対値
printf("5 ^ 3 = %f\n", 5 ** 3);
printf("root 5 = %f\n", sqrt(5));
printf("|-5| = %f\n", abs(-5));
include Math
# ラジアンを求めるモジュールメソッド
module Math
def toRadians(d)
return d * Math::PI / 180
end
end
# 正弦 余弦 正接
puts "sin(60) = #{sin(toRadians(60))}"
puts "cos(60) = #{cos(toRadians(60))}"
puts "tan(60) = #{tan(toRadians(60))}"
# 指数 対数
puts "exp(100) = #{exp(100)}"
puts "log10(100) = #{log10(100)}"
# べき乗 平方根 絶対値
puts "5 ^ 3 = #{5 ** 3}"
puts "root 5 = #{sqrt(5)}"
puts "|-5| = #{-5.abs}"
最終更新日 : 2005.05.29
Number /
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
copyright 2000-2005
ARGIUS project