C ++のlrint()およびllrint()
このセクションでは、C ++でのlrint()とllring()について説明します。まず、lrint()について説明しましょう。
lrint()関数は、現在の丸めモードを使用して、引数の小数部の指定された値を整数値に丸めるために使用されます。現在のモードは、fesetround()。> =
を使用して決定されます。このlrint()関数は、入力パラメーターとしてdouble、float、またはinteger値を取り、小数部分を整数部分に丸めることによってlongint値を返します。
例
#include <cfenv>
#include <cmath>
#include <iostream>
using namespace std;
main() {
int x = 40;
long int res;
fesetround(FE_DOWNWARD); // setting rounding direction to DOWNWARD as downward
res = lrint(x);
cout << "Downward rounding of " << x << " is " << res << endl;
}です。 出力
Downward rounding of 40.0235 is 40
llrint()関数は、現在の丸めモードを使用して、引数の小数部の指定された値を整数値に丸めるために使用されます。現在のモードは、fesetround()を使用して決定されます。
このlrint()関数は、入力パラメーターとしてdouble、float、またはinteger値を取り、小数部分を整数部分に丸めることによってlonglongint値を返します。
例
#include <cfenv>
#include <cmath>
#include <iostream>
using namespace std;
main(){
double a;
long int res;
fesetround(FE_UPWARD); //set rounding direction to upward
a = 40.3;
res = llrint(a);
cout << "Upward rounding of " << a << " is " << res << endl;
fesetround(FE_DOWNWARD); //set rounding direction to downward
a = 40.88;
res = llrint(a);
cout << "Downward rounding of " << a << " is " << res << endl;
} 出力
Upward rounding of 40.3 is 41 Downward rounding of 40.88 is 40
-
sin(x)およびcos(x)の値を計算するC++プログラム
入力を角度として指定すると、指定した角度に対応するsin(x)とcos(x)の値を計算し、結果を表示することがタスクになります。 Sin(x)の場合 Sin(x)は、x角度の値を計算するために使用される三角関数です。 式 $$ \ sin(x)=\ displaystyle \ sum \ Limits_ {k =0} ^ \ infty \ frac {(-1)^ {k}} {(2k + 1)!} x ^ {2k + 1} $ $ Cos(x)の場合 Cos(x)は、x角度の値を計算するために使用される三角関数です。 式 $$ \ cos(x)=\ displays
-
++のインクリメントとデクリメント-C++の演算子
インクリメント演算子++はオペランドに1を加算し、デクリメント演算子--はオペランドから1を減算します。だから、 x = x+1; is the same as x++; 同様に、 x = x-1; is the same as x--;と同じです インクリメント演算子とデクリメント演算子はどちらも、オペランドの前(プレフィックス)または後(ポストフィックス)のいずれかになります。 x = x+1; can be written as ++x; 式の一部としてインクリメントまたはデクリメントを使用する場合、接頭辞と接尾辞の形式に重要な違いがあることに注意してください。プレフィックス形式を