Quick, prove you can code!

Quick, prove you can code!

Write a function that adds two numbers together and returns the result.

Attached: F0C596AF-A6C6-4B33-90BD-D79C6E66486E.jpg (1170x1695, 958.08K)

int add(int a, int b) {
return a + b;
}

/thread

>he thinks this is the only way to add two numbers together

That wasn't the question fuckwit

But like what if they arent whole numbers?

You didn't think about overflow or underflow here. You need to use error codes to indicate potential issues with the calculation. What if I add INT_MAX and INT_MAX together?

(a,b)=>a+b

int sir(int a, int b) {
int redeem = a;
for (int i = 0; i < abs(b); i++) {
b > -1 ? redeem++ : redeem--;
}
return redeem;
}

int add(int a, int b) {
for(int i=0;i

Attached: rs35100_dsc_0715.1200x0.jpg (1200x800, 209.44K)

if you use INT_MAX as both arguments you deserve to crash

What kind of numbers?

int add (int a, int b)
{
int sum = a += b;
return a;
}

The correct result was not specified in the instructions, so it is fine.

string sum(string a, string b)
{
if
(
a.size() < b.size()
)
{
swap
(
a,
b
);
}

int j = a.size()-1;
for
(
int i=b.size()-1;
i>=0;
i--,
j--
)
a[j]+=
(
b[i]-'0'
);

for
(
int i=a.size()-1;
i>0;
i--
)
{
if
(
a[i] > '9'
)
{
int d = a[i]-'0';
a[i-1] =
(
(
a[i-1]-'0'
)
+ d/10
) + '0';
a[i] =
(
d%10
)
+'0';
}
}
if
(
a[0] > '9'
)
{
string k;
k+=a[0];
a[0] = (
(
a[0]-'0'
)
%10
)
+'0';
k[0] =
(
(
k[0]-'0')/10
)
+'0';
a = k+a;
}
return a;
}

print("hello 4chads")

surreal numbers

I am fortunate to have never used .NET

public BigDecimal add(BigDecimal val1, BigDecimal val2) {
return Stream.of(val1, val2).reduce(BigDecimal::add).get();
}

using Microsoft.Extensions.Options;
using static System.Console;

(int n1, int n2) = ParseInput();

IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddSingleton()
.Configure(o =>
{
o.Number1 = n1;
o.Number2 = n2;
});
})
.Build();

Adder adder = host.Services.GetRequiredService();
WriteLine(adder.Result);

static (int, int) ParseInput()
{
string[] arr = ReadLine().Split("+");
return (int.Parse(arr[0]), int.Parse(arr[1]));
}
internal class Adder
{
private readonly AdderOptions options;
public int Result => options.Number1 + options.Number2;
public Adder(IOptions options)
{
this.options = options.Value;
}
}
internal class AdderOptions
{
public static string OptionsName => "AdderOptions";
public int Number1 { get; set; }
public int Number2 { get; set; }
}

(+)

I keked so hard at this one. Typical C# code you find in companies

```
const add = () => 3 + 7;
```
Most effecient, allocates no new memory. Satisfies requirements.

Attached: indian coding.jpg (594x768, 94.26K)

def function_that_returns_two_numbers_added():
number_1 = 23
number_2 = 55
two_numbers_added = number_1 + number_2
return two_numbers_added