1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Luden [163]
3 years ago
6

Write a program numbers.cpp that defines a function bool isDivisibleBy(int n, int d); If n is divisible by d, the function shoul

d return true, otherwise return false. For example: isDivisibleBy(100, 25)

Computers and Technology
2 answers:
balandron [24]3 years ago
4 0

Answer:

Here is the function in Python:

def isDivisibleBy(n,d):

   if(n%d)==0:

       return True;

   else:

       return False;    

Explanation:

Lets see how this works. You can call this function in main program to check if this function isDivisibleBy() works properly.

if(isDivisibleBy(8,2)==True):

   print("It is divisible")

else:

   print(" It is not divisible")

Now the bool function isDivisibleBy() takes two arguments, n and d. bool function returns either true or false. If the number in n is divisible by d the function returns true otherwise it returns false. The number n is completely divisible by d when the remainder of this division is 0. So modulus operator is used to check if n is completely divisible by d.

In main program if condition is used which calls the isDivisibleBy() function and checks if the function returns true. The function is passed two values 8 and 2 where 8 is n and 2 is d. If this condition evaluates to true then the message displayed in output is: It is divisible. When the if condition evaluates to false the messages displayed in output is: It is not divisible.

The program along with its output is attached in the screen shot.

Misha Larkins [42]3 years ago
3 0

Answer:

  1. bool isDivisibleBy(int n, int d){
  2.    
  3.    if(n % d == 0){
  4.        return true;
  5.    }
  6.    else{
  7.        return false;
  8.    }
  9. }

Explanation:

To check if n is divisible by d, we can use modulus operator such as %. If n % d equal to 0, this means n is divisible by d. Modulus operator is to calculate the remainder obtained from a division. If a number is divisible by another number, the remainder will be 0.

By making use of this concept we can create if and else statement to check if n % d is equal to 0, return true (divisible) else return false (not divisible).

You might be interested in
Importance of Microsoft access​
nignag [31]

Answer:

Microsoft Access is important because it  decreases the amount of time it takes to exchange information between Microsoft Office applications.

<em> - Hope this helps!</em>

<em />

6 0
4 years ago
Define Indentation
weqwewe [10]
B. Distance between page margin and edges of page.
4 0
3 years ago
How can i underline a simple text on word?
Fiesta28 [93]

Answer:

Underneath the font box there should be a capital U that is underlined.

Highlight the text you want to underline and click the U button.

6 0
3 years ago
Read 2 more answers
10. A loop statement is given as:
nirvana33 [79]

Answer: a. None

Explanation:

The loop will not run as the condition always returns false.

i=10 and the condition given: i<10 which is false always. So, the loop will not run.

8 0
3 years ago
When you block a number can they still text??
noname [10]
When a blocked number tries to send you a text message, it won’t go through, and they will likely never see the “delivered” note. On your end, you’ll see nothing at all. As far as phone calls are concerned, a blocked call goes directly to voice mail. On your end, you’ll get a special “blocked messages” folder in your voice mail inbox if they leave a message, but you won’t get a notification they called.
5 0
3 years ago
Other questions:
  • Silver, lead, and hydrogen are examples of what type of matter?
    12·1 answer
  • Match the terms related to the web with their explanations
    6·1 answer
  • You have implemented a network where each device provides shraed files with all other devices on the network. what type of netwo
    10·1 answer
  • Encryption has a remarkably long and varied history. Spies have been using it to convey secret messages ever since there were se
    7·1 answer
  • _____ check to see what links are on the user's web page and make sure they work; if a link is broken, they identify it and incl
    8·2 answers
  • In PumaMart system, why an initial offer is not necessary at the beginning of negotiation?
    6·1 answer
  • Which of the following is the best way to locate books and research from all over the United States and abroad?
    9·2 answers
  • design a relational database in EER for bike helmets and their reviews. a bike helmet has a name and color attributes. a bike co
    12·1 answer
  • Write a function named minMax() that accepts three integers arguments from the keyboard and finds the smallest and largest integ
    5·1 answer
  • Javier downloads an illustration from an online Image library and modifies it for his purposes. The illustration he downloads is
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!