A+B: Difference between revisions
Content added Content deleted
m (Alphabetize) |
(→Solution: whitespace improvements) |
||
Line 25: | Line 25: | ||
|} |
|} |
||
= |
= Solutions = |
||
=={{header|C}}== |
=={{header|C}}== |
||
⚫ | |||
⚫ | |||
⚫ | |||
#include <stdio.h> |
#include <stdio.h> |
||
main() |
main() |
||
Line 50: | Line 49: | ||
printf("%d\n", a + b); |
printf("%d\n", a + b); |
||
return 0; |
return 0; |
||
⚫ | |||
} |
|||
⚫ | |||
=={{header|C++}}== |
=={{header|C++}}== |
||
<lang cpp> |
<lang cpp>// Standard input-output streams |
||
// Standard input-output streams |
|||
#include <iostream> |
#include <iostream> |
||
using namespace std; |
using namespace std; |
||
Line 64: | Line 61: | ||
cout << a + b << endl; |
cout << a + b << endl; |
||
return 0; |
return 0; |
||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
// Output file: output.txt |
// Output file: output.txt |
||
#include <fstream> |
#include <fstream> |
||
Line 79: | Line 74: | ||
out << a + b << endl; |
out << a + b << endl; |
||
return 0; |
return 0; |
||
⚫ | |||
} |
|||
⚫ | |||
=={{header|C_sharp|C#}}== |
=={{header|C_sharp|C#}}== |
||
<lang csharp> |
<lang csharp>using System.IO; |
||
using System.IO; |
|||
class plus { |
class plus { |
||
Line 98: | Line 91: | ||
} |
} |
||
} |
} |
||
⚫ | |||
} |
|||
⚫ | |||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
Line 106: | Line 98: | ||
[ string>number ] bi@ + |
[ string>number ] bi@ + |
||
number>string print ;</lang> |
number>string print ;</lang> |
||
<pre> |
|||
( scratchpad ) a+b |
|||
2 2 |
|||
4 |
|||
⚫ | |||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang text> |
<lang text>import Control.Monad |
||
import Control.Monad |
|||
main = liftM2 (+) readLn readLn >>= print |
main = liftM2 (+) readLn readLn >>= print</lang> |
||
</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
Line 156: | Line 147: | ||
out.println(nextInt() + nextInt()); |
out.println(nextInt() + nextInt()); |
||
} |
} |
||
⚫ | |||
} |
|||
</lang> |
|||
<lang java>import java.io.*; |
<lang java>import java.io.*; |
||
Line 180: | Line 170: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
<lang pascal> |
<lang pascal>var |
||
var |
|||
a, b: integer; |
a, b: integer; |
||
begin |
begin |
||
readln(a, b); |
readln(a, b); |
||
writeln(a + b); |
writeln(a + b); |
||
end. |
end.</lang> |
||
</lang> |
|||
Same with input from file <tt>input.txt</tt> and output from file <tt>output.txt</tt>. |
Same with input from file <tt>input.txt</tt> and output from file <tt>output.txt</tt>. |
||
<lang pascal> |
<lang pascal>var |
||
var |
|||
a, b: integer; |
a, b: integer; |
||
begin |
begin |
||
Line 199: | Line 186: | ||
close(input); |
close(input); |
||
close(output); |
close(output); |
||
end. |
end.</lang> |
||
</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
Line 208: | Line 194: | ||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
<lang scheme> |
<lang scheme>(write (+ (read) (read)))</lang> |
||
(write (+ (read) (read))) |
|||
</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
===Console=== |
===Console=== |
||
<lang python> |
<lang python>r = raw_input().split() |
||
⚫ | |||
r = raw_input().split() |
|||
⚫ | |||
</lang> |
|||
===File=== |
===File=== |
||
<lang python> |
<lang python>fin = open("input.txt", "r") |
||
fin = open("input.txt", "r") |
|||
fout = open("output.txt","w") |
fout = open("output.txt","w") |
||
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> |
||
</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
⚫ | |||
<lang ruby> |
|||
⚫ | |||
</lang> |