A+B: Difference between revisions

Content deleted Content added
Add Factor
m Alphabetize
Line 26:
 
= 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}}==
Line 102 ⟶ 80:
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>
 
=={{header|Java}}==
<lang java>import java.util.*;
import java.util.*;
 
public class Sum2 {
Line 113 ⟶ 126:
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.
 
<lang java>import java.io.*;
import java.io.*;
import java.util.*;
 
Line 168 ⟶ 179:
}</lang>
 
=={{header|C_sharp|C#Pascal}}==
<lang csharppascal>
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>
 
=={{header|Factor}}==
<lang factor>: a+b ( -- )
readln " " split1
[ string>number ] bi@ +
number>string print ;</lang>
 
( scratchpad ) a+b
2 2
4
 
=={{header|PicoLisp}}==
Line 219 ⟶ 224:
r = fin.readline().split()
fout.write(str(int(r[0]) + int(r[1])))
</lang>
 
=={{header|Haskell}}==
<lang text>
import Control.Monad
 
main = liftM2 (+) readLn readLn >>= print
</lang>