C#の数値
C#の数値には、int型を使用します。正または負の整数である整数を表します。
数学演算子+−
を使用してC#で2つの整数を追加する方法を見てみましょう。using System;
using System.Linq;
class Program {
static void Main() {
int x = 20;
int y = 30;
int sum = 0;
sum = x + y;
Console.WriteLine(sum);
}
} ここで、これらの数学演算子の順序、つまり演算子の優先順位について学びましょう。
演算子の優先順位は、式内の用語のグループ化を決定します。これは、式の評価に影響します。特定の演算子は他の演算子よりも優先されます。たとえば、乗算演算子は加算演算子よりも優先されます。
たとえば、x =9 + 2 * 5;ここでは、演算子*の優先順位が+よりも高いため、xには55ではなく19が割り当てられます。したがって、最初の評価は2 * 5に対して行われ、次に9が追加されます。
以下は、演算子の順序を示す例です-
例
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
int a = 200;
int b = 100;
int c = 150;
int d = 50;
int res;
res = (a + b) * c / d;
Console.WriteLine("Value of (a + b) * c / d is : {0}", res);
res = ((a + b) * c) / d;
Console.WriteLine("Value of ((a + b) * c) / d is : {0}", res);
res = (a + b) * (c / d);
Console.WriteLine("Value of (a + b) * (c / d) : {0}",res);
res = a + (b * c) / d;
Console.WriteLine("Value of a + (b * c) / d : {0}",res);
Console.ReadLine();
}
}
} -
Javaでの数値配列のLCM
L.C.M.または2つの値の最小公倍数は、両方の値の倍数である最小の正の値です。 たとえば、3と4の倍数は次のとおりです。 3→3、6、9、12、15 ... 4→4、8、12、16、20 ... 両方の最小公倍数は12であるため、3と4のLCMは12です。 プログラム 次の例では、数値の配列のLCMを計算します。 public class LCMofArrayOfNumbers { public static void main(String args[]) { int[] myArray = {25, 50,
-
JavaScript番号の例
以下はJavaScriptの数字の例です- 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body