Question: Language: C++ Add to the program the following function : bool divByDigitSum( unsigned int n) That returns True if the integer received by the parameter
Language: C++
Add to the program the following function :
bool divByDigitSum( unsigned int n)
That returns True if the integer received by the parameter is divisible by the sum of its digits, or false if it doesnt.
For example, divByDigitSum(12) must return because 12 is divisible by 3.
divByDigitSum(15) returns false since is not divisible by 6.
Do not convert the integer into a string.
Here is the main program
main.cpp
------------------------------------------------------------------------------------------- #define CATCH_CONFIG_MAIN // This tells Catch to provide a main()
#include "catch_amalgamated.hpp"
unsigned int Factorial( unsigned int number ) {
return number <= 1 ? number : Factorial(number-1)*number;
}
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
