Cody

Problem 44513. Add all the numbers between two limits (inclusive)

Solution 3355283

Submitted on 24 Oct 2020 by Rafael S.T. Vieira
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   Pass
a = 1; b = 2; dt = 'uint64'; s_correct = 3; s = summation(a, b, dt); assert( isequal(s, s_correct) )

2   Pass
a = 1; b = 2; dt = 'int8'; s_correct = 3; s = summation(a, b, dt); assert( isequal(s, s_correct) )

3   Pass
a = 1; b = 2; dt = 'single'; s_correct = 12582913.5; s = summation(a, b, dt); assert( abs(s - s_correct) < 2 )

4   Pass
a = 1; b = 2; dt = 'double'; s_correct = 6755399441055746; s = summation(a, b, dt); assert( abs(s - s_correct) < 2 )

5   Pass
a = 2; b = 3; dt = 'int32'; s_correct = 5; s = summation(a, b, dt); assert( isequal(s, s_correct) )

6   Pass
a = 2; b = 3; dt = 'uint16'; s_correct = 5; s = summation(a, b, dt); assert( isequal(s, s_correct) )

7   Pass
a = 2; b = 3; dt = 'single'; s_correct = 10485762.5; s = summation(a, b, dt); assert( abs(s - s_correct) < 2 )

8   Pass
a = 2; b = 3; dt = 'double'; s_correct = 5629499534213122; s = summation(a, b, dt); assert( abs(s - s_correct) < 2 )

9   Pass
a = 4; b = 5; dt = 'int64'; s_correct = 9; s = summation(a, b, dt); assert( isequal(s, s_correct) )

10   Pass
a = 4; b = 5; dt = 'uint8'; s_correct = 9; s = summation(a, b, dt); assert( isequal(s, s_correct) )

11   Pass
a = 4; b = 5; dt = 'single'; s_correct = 9437188.5; s = summation(a, b, dt); assert( abs(s - s_correct) < 2 )

12   Pass
a = 4; b = 5; dt = 'double'; s_correct = 5066549580791812; s = summation(a, b, dt); assert( abs(s - s_correct) < 2 )

13   Pass
a = 8; b = 9; dt = 'uint32'; s_correct = 17; s = summation(a, b, dt); assert( isequal(s, s_correct) )

14   Pass
a = 8; b = 9; dt = 'int16'; s_correct = 17; s = summation(a, b, dt); assert( isequal(s, s_correct) )

15   Pass
a = 8; b = 9; dt = 'single'; s_correct = 8912904.5; s = summation(a, b, dt); assert( abs(s - s_correct) < 2 )

16   Pass
a = 8; b = 9; dt = 'double'; s_correct = 4785074604081160; s = summation(a, b, dt); assert( abs(s - s_correct) < 2 )

17   Pass
a = 20; b = 22; dt = 'int32'; s_correct = 63; s = summation(a, b, dt); assert( isequal(s, s_correct) )

18   Pass
a = 20; b = 22; dt = 'double'; s_correct = 11821949021847573; s = summation(a, b, dt); assert( abs(s - s_correct) < 4 )

19   Pass
a = 20; b = 22; dt = 'single'; s_correct = 22020117; s = summation(a, b, dt); assert( abs(s - s_correct) < 4 )

20   Pass
a = 20; b = 30; dt = 'uint16'; s_correct = 275; s = summation(a, b, dt); assert( isequal(s, s_correct) )

21   Pass
a = 20; b = 30; dt = 'double'; s_correct = 70368744177664025; s = summation(a, b, dt); assert( abs(s - s_correct) < 32 )

22   Pass
a = 20; b = 30; dt = 'single'; s_correct = 131072025; s = summation(a, b, dt); assert( abs(s - s_correct) < 32 )

23   Pass
a = 1; b = 17; dt = 'uint8'; s_correct = 153; s = summation(a, b, dt); assert( isequal(s, s_correct) )

24   Pass
a = 1; b = 17; dt = 'double'; s_correct = 105975328731561993; s = summation(a, b, dt); assert( abs(s - s_correct) < 64 )

25   Pass
a = 1; b = 17; dt = 'single'; s_correct = 197394441; s = summation(a, b, dt); assert( abs(s - s_correct) < 64 )

26   Pass
a = -130; b = -126; dt = 'int32'; s_correct = -640; s = summation(a, b, dt); assert( isequal(s, s_correct) )

27   Pass
a = -130; b = -126; dt = 'double'; s_correct = -26951229020045440; s = summation(a, b, dt); assert( abs(s - s_correct) < 16 )

28   Pass
a = -130; b = -126; dt = 'single'; s_correct = -50200704; s = summation(a, b, dt); assert( abs(s - s_correct) < 16 )

Suggested Problems

More from this Author31

Community Treasure Hunt

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

Start Hunting!