Naavin
1
#include "difference_of_squares.h"
unsigned int sum_of_squares(unsigned int number)
{
return (number * (number + 1) * (2 * number + 1)) / 6;
}
unsigned int square_of_sum(unsigned int number)
{
unsigned int sum = (number * (number + 1)) / 2;
return sum*sum;
}
unsigned int difference_of_squares(unsigned int number)
{
return (sum_of_squares(number) - square_of_sum(number));
}
I think the issue is with return data type although I have used data type mentioned in header files.
Hi!
Please post code snippets in a code block. Otherwise parts of the code might be rendered incorrectly, e.g. double quotes become fancy.
Also, if you need help with an error, please post the error message, too (in a code block as well.)
Instead of me telling you what the issue is, I’d like to help you figure it out for yourself. Is that OK?
The test_difference_of_squares_5
calls difference_of_squares(5)
and expects the result to be 170
.
- Do you understand why that is the correct result?
- What does your implementation of
difference_of_squares
return?
- Do you understand why it returns that value?
- Do you understand why that’s an issue?
- Can you find a way to fix that issue?
1 Like
Naavin
3
Thank you for sharing about code block markdown.
I got the issue and resolved it 
1 Like