C ++のdiv()関数
C / C++ライブラリ関数div_tdiv(int numer、int denom)は、numer(numerator)をdenom(分母)で除算します。以下はdiv()関数の宣言です。
div_t div(int numer, int denom)
パラメータは分子と分母です。この関数は、2つのメンバーを持つ
例
#include <iostream>
#include <cstdlib>
using namespace std;
int main () {
div_t output;
output = div(27, 4);
cout << "Quotient part of (27/ 4) = " << output.quot << endl;
cout << "Remainder part of (27/4) = " << output.rem << endl;
output = div(27, 3);
cout << "Quotient part of (27/ 3) = " << output.quot << endl;
cout << "Remainder part of (27/3) = " << output.rem << endl;
return(0);
} 出力
Quotient part of (27/ 4) = 6 Remainder part of (27/4) = 3 Quotient part of (27/ 3) = 9 Remainder part of (27/3) = 0
-
C++の純粋関数
純粋関数は、同じ引数値に対して常に同じ結果を返します。結果を返すだけで、引数の変更、I / Oストリーム、出力の生成などの追加の副作用はありません。 いくつかの純粋関数はsin()、strlen()、sqrt()、max()、pow()、floor()などです。いくつかの純粋関数はrand()、time()などです。 純粋関数のいくつかを実証するためのいくつかのプログラムは次のとおりです- strlen() strlen()関数は、文字列の長さを見つけるために使用されます。これは、次のプログラムで示されています- 例 #include<iostream> #include&
-
C ++のswap()関数
swap()関数は、2つの数値を交換するために使用されます。この関数を使用すると、2つの数値を交換するために3番目の変数は必要ありません。 C ++言語でのswap()の構文は次のとおりです。 void swap(int variable_name1, int variable_name2); 変数に値を割り当てるか、ユーザー定義の値を渡すと、変数の値が交換されますが、変数の値は実際の場所では同じままです。 これがC++言語でのswap()の例です 例 #include <bits/stdc++.h> using namespace std; int main() { &nb