Arithmetic operators



Using some basic Arithmetic operators and StrToIntDef, div, mod.
Pas2JS pascal source code
{ filename: unit1.pas } var n, i: Integer; begin n := 10; n := n * 10; for i := 1 to n do begin if (i mod 3) = 0 then Continue; if (i mod 5) = 1 then Continue; if (i mod 7) = 0 then Continue; if i > n div 2 then Break; Writeln(IntToStr(i)); end; // it will output: {2,4,5,8,10,13,17,19,20,22,23,25,29,32,34,37,38,40,43,44,47,50} n := 142; Writeln('142 div 10 = ' + IntToStr(142 div 10)); // 14 Writeln('142 mod 10 = ' + IntToStr(142 mod 10)); // 2 i := 10; Writeln(IntToStr(n + i)); // 100 + 10 = 110 Writeln(IntToStr(n - i)); // 100 - 10 = 90 Writeln(IntToStr(n + n * i - i)); // (100 + 100 * 10 - 10) = 1090 Writeln(IntToStr((n + n) * (i - i))); // (100+100) x (10-10) = 0 Writeln(IntToStr((n + i) * (n - i))); // (100+10) x (100-10) = 9900 Writeln(IntToStr(n + n div i)); // 100 + (100 / 10) = 110 Writeln(IntToStr(n div i + n)); // (100 / 10) + 100 = 110 { filename: unit2.pas } var a := StrToIntDef(w3_Prompt('Enter 1st number','0'),0); var b := StrToIntDef(w3_Prompt('Enter 2nd number','0'),0); WriteLn(Format('%d + %d = %d', [a, b, a + b])); WriteLn(Format('%d - %d = %d', [a, b, a - b])); WriteLn(Format('%d * %d = %d', [a, b, a * b])); WriteLn(Format('%d / %d = %d', [a, b, a div b])); WriteLn(Format('%d mod %d = %d', [a, b, a mod b])); WriteLn(Format('%d ^ %d = %d', [a, b, Trunc(Power(a, b))]));