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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!