Problem 8. Add two numbers
Solution Stats
Problem Comments

41 Comments
A quick easy start! xD
I tried. But caught with error.
it is very easy to abuse the solution map by writing a correct solution with a lot of useless code before it. I tested this and got the solution map rescaled to absurdity (and I see I'm not the only one). Please correct this.
Easy start...
1st try :)
great
good job
nice q
nice
I did it
good
so fun!!!!!!
nice
Good one.
quick and easy start
nice
Easy Start
function c = addo(a,b)
c= a+b;
end
%I did the above, Why does it say it's wrong?
c=a+b
Oier said it's really rudimental!
function sum
c=a+b;
end
good
just to appreciate the moment that there are 69 likes for this simple question
c=a+b
good
a=given value;
b=given valve;
c=a+b;
display('the ans c is',num2str(c));
cool
straight forward, warm up question
Very easy! Great warmup
My favorite problem
got it
good intro problem
I like this problem
great way to start
easy
Good problem
Very nice
hey, could you tell me where is the command window to solve this problem?
how to solve these problems.
easy
Simple
Very simple
Solution Comments

1 Comment
This is the solution with the smallest size I don't know why they don't agree

1 Comment
a little tricky

1 Comment
This is a good starter problem, I was kind of confused by the function file though at first since you can't see the script

1 Comment
GOOD

1 Comment
just for example
a=1
b=2
c=a+b
output c=3

1 Comment
wow amazing problem, very challenging

1 Comment
I like this task :)

1 Comment
very easy

2 Comments
I like the approach these questions take. It is helping me understand some parts of Matlab I have had issues with in the the past.
good job guys

1 Comment
A very good starting problem on functions

1 Comment
easy right now

1 Comment
bingo!!!

1 Comment
good

1 Comment
Nice!

1 Comment
Why is this wrong here? I checked using matlab on my laptop and it works.

2 Comments
this is cool!
Good Job!

1 Comment
got it!

1 Comment
interesting

2 Comments
gud..
good one!

1 Comment
Good Job!

1 Comment
easy

1 Comment
nice

1 Comment
:D

1 Comment
This was a good problem/solution to start out on.

1 Comment
this is a bad solution

3 Comments
What is wrong with this solution?
the code is wrong because the function name should be 'add_two_numbers'.
In the test code the are evaluating:
assert(isequal(add_two_numbers(a,b),c_correct))
So if your function is called 'sum' it wont be called by the test script.
idk

1 Comment
Try writing out the equation you want to use, with 'c =' on the left, and 'a' and 'b' on the right. You don't need to define c =.., a =.., or b =.. in the function.
Good luck!

6 Comments
hello brian !
I'd like to know how your solution size is 9.
Can you please let me know how you did it ?
Thanks !
Why is this of size 9? The long string?
For the record, I don't recommend reading this, but here goes:
My solution is
function ans = add_two_numbers(varargin)
system 'echo "function ans = assert(~), true;" > ./assert.m';
It works by redefining the assert() function that the test suite uses to always return true. This strategy can be used to solve any problem. Many of the leading solutions to problems are hacks like this. It's actually quite fascinating to think of ways to "cheat" the system
Ah, that makes so much more sense! Thanks for explaining Brian.
Why is the following not accepted ?
add_two_numbers = @(x,y) x+y;
Solution size is also 9, but the solution is not recognized. Just wondering why, as it works in MATLAB.
@Danilo Maybe the website prevents anonymous functions.

1 Comment
This challenge was quite simple. Good for beginners.

1 Comment
self explainable code. thanks to cody team

1 Comment
really enjoy

2 Comments
What the...?
from where could i learn this regexp

1 Comment
Cool

1 Comment
Error: Undefined function 'add_two_numbers' for input arguments of type 'double'

4 Comments
this is not a function?
cheat.
Can you explain how does it work?
why this is working?
It was a system error. I rescored the solution, and that did the right thing.

1 Comment
Har har

1 Comment
fast fourier transform should be fast anywhere,right?? why not here?xaxa Funny approach

1 Comment
Of course, c = a+b; is entirely correct, using the operator form for addition. plus(a,b) uses the function form.
Problem Recent Solvers31915
Suggested Problems

714 Solvers

Make a random, nonrepeating vector.
4632 Solvers

Create an nbyn null matrix and fill with ones certain positions
406 Solvers

577 Solvers

417 Solvers
More from this Author95
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!