Cody

Problem 2274. Find the square of the sum of the digits of a number

Solution 3218073

Submitted on 15 Oct 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Fail
x = 35431; y_correct = 256; assert(isequal(sq_sum(x),y_correct))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in sq_sum (line 4) y=y+str2num(x); Error in Test1 (line 3) assert(isequal(sq_sum(x),y_correct))

2   Fail
x = -431; y_correct = 64; assert(isequal(sq_sum(x),y_correct))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in sq_sum (line 4) y=y+str2num(x); Error in Test2 (line 3) assert(isequal(sq_sum(x),y_correct))

Suggested Problems

More from this Author9

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!