A+B: Difference between revisions
Content added Content deleted
(Add Factor) |
m (Alphabetize) |
||
Line 26: | Line 26: | ||
= Solution = |
= Solution = |
||
=={{header|Pascal}}== |
|||
<lang pascal> |
|||
var |
|||
a, b: integer; |
|||
begin |
|||
readln(a, b); |
|||
writeln(a + b); |
|||
end. |
|||
</lang> |
|||
Same with input from file <tt>input.txt</tt> and output from file <tt>output.txt</tt>. |
|||
<lang pascal> |
|||
var |
|||
a, b: integer; |
|||
begin |
|||
reset(input, 'input.txt'); |
|||
rewrite(output, 'output.txt'); |
|||
readln(a, b); |
|||
writeln(a + b); |
|||
close(input); |
|||
close(output); |
|||
end. |
|||
</lang> |
|||
=={{header|C}}== |
=={{header|C}}== |
||
Line 102: | Line 80: | ||
return 0; |
return 0; |
||
} |
} |
||
</lang> |
|||
=={{header|C_sharp|C#}}== |
|||
<lang csharp> |
|||
using System.IO; |
|||
class plus { |
|||
public static void Main(string[] args) { |
|||
int a,b; |
|||
{ |
|||
StreamReader reader = new StreamReader("plus.in"); |
|||
a = int.Parse(reader.ReadLine()); |
|||
b = int.Parse(reader.ReadLine()); |
|||
StreamWriter writer = new StreamWriter("plus.out"); |
|||
writer.WriteLine(a+b); |
|||
writer.Close(); |
|||
} |
|||
} |
|||
} |
|||
</lang> |
|||
=={{header|Factor}}== |
|||
<lang factor>: a+b ( -- ) |
|||
readln " " split1 |
|||
[ string>number ] bi@ + |
|||
number>string print ;</lang> |
|||
( scratchpad ) a+b |
|||
2 2 |
|||
4 |
|||
=={{header|Haskell}}== |
|||
<lang text> |
|||
import Control.Monad |
|||
main = liftM2 (+) readLn readLn >>= print |
|||
</lang> |
</lang> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
<lang java> |
<lang java>import java.util.*; |
||
import java.util.*; |
|||
public class Sum2 { |
public class Sum2 { |
||
Line 113: | Line 126: | ||
System.out.println(in.nextInt() + in.nextInt()); // Standard output |
System.out.println(in.nextInt() + in.nextInt()); // Standard output |
||
} |
} |
||
}</lang> |
|||
} |
|||
</lang> |
|||
Object of [[class]] Scanner works slow enough, because of that contestants prefer to avoid its use. Often, longer solution works faster and easily scales to problems. |
Object of [[class]] Scanner works slow enough, because of that contestants prefer to avoid its use. Often, longer solution works faster and easily scales to problems. |
||
<lang java> |
<lang java>import java.io.*; |
||
import java.io.*; |
|||
import java.util.*; |
import java.util.*; |
||
Line 168: | Line 179: | ||
}</lang> |
}</lang> |
||
=={{header| |
=={{header|Pascal}}== |
||
<lang |
<lang pascal> |
||
var |
|||
using System.IO; |
|||
a, b: integer; |
|||
begin |
|||
class plus { |
|||
readln(a, b); |
|||
public static void Main(string[] args) { |
|||
writeln(a + b); |
|||
int a,b; |
|||
end. |
|||
{ |
|||
</lang> |
|||
StreamReader reader = new StreamReader("plus.in"); |
|||
Same with input from file <tt>input.txt</tt> and output from file <tt>output.txt</tt>. |
|||
a = int.Parse(reader.ReadLine()); |
|||
<lang pascal> |
|||
b = int.Parse(reader.ReadLine()); |
|||
var |
|||
StreamWriter writer = new StreamWriter("plus.out"); |
|||
a, b: integer; |
|||
writer.WriteLine(a+b); |
|||
begin |
|||
writer.Close(); |
|||
reset(input, 'input.txt'); |
|||
} |
|||
rewrite(output, 'output.txt'); |
|||
} |
|||
readln(a, b); |
|||
} |
|||
writeln(a + b); |
|||
close(input); |
|||
close(output); |
|||
end. |
|||
</lang> |
</lang> |
||
=={{header|Factor}}== |
|||
<lang factor>: a+b ( -- ) |
|||
readln " " split1 |
|||
[ string>number ] bi@ + |
|||
number>string print ;</lang> |
|||
( scratchpad ) a+b |
|||
2 2 |
|||
4 |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
Line 219: | Line 224: | ||
r = fin.readline().split() |
r = fin.readline().split() |
||
fout.write(str(int(r[0]) + int(r[1]))) |
fout.write(str(int(r[0]) + int(r[1]))) |
||
</lang> |
|||
=={{header|Haskell}}== |
|||
<lang text> |
|||
import Control.Monad |
|||
main = liftM2 (+) readLn readLn >>= print |
|||
</lang> |
</lang> |
||