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
Technology is defined as human ________________ in action that involves the generation of knowledge and processes to develop sys
Alenkasestr [34]

Answer:

Innovation:

Explanation:

Technology is defined as human innovation in action that involves the generation of knowledge and processes to develop systems that solve problems and extend human capabilities.

To innovate is to make changes in something established, especially by introducing new methods, ideas, or products.

5 0
2 years ago
12. In 2009, __________ of all pedestrian fatalities were caused by impaired drivers
makvit [3.9K]
3% of pedestrian fatalities were caused by impaired drivers  
4 0
3 years ago
Read 2 more answers
OSHA standards appear in the ___________ and are then broken down into ____________.
miskamm [114]
OSHA standards appear in the <span>Code of Federal Regulations (CFR) and are then broken down into Parts</span>
3 0
3 years ago
A spreadsheet will complete a variety of mathematical formulas for the user.<br><br> True or false
Lady bird [3.3K]

Answer: True

Explanation:

A spreadsheet will complete any formula as long as its entered by the user

6 0
3 years ago
Read 2 more answers
2) Phát biểu nào sau đây là sai khi gán hiệu ứng cho các đối tượng trên slide?
raketka [301]
Pls translate into english
8 0
3 years ago
Other questions:
  • Which osi reference model layer includes all programs on a computer that interact with the network?
    13·1 answer
  • Write a program that opens a text file and reads its contents into a queue of characters. The program should then dequeue each c
    11·1 answer
  • In which career does the level of education vary the most?
    13·2 answers
  • To create a small research essay (no more than 1 page) about coronavirus. You will need to have at least two sources and you wil
    15·1 answer
  • Which search engine optimization technique involves sending data describing your web site to the search engines and then paying
    13·1 answer
  • Pls help me with this pls
    7·2 answers
  • Which is the purpose of adding B-Roll footage to a sequence?
    10·1 answer
  • Draw algorithm and flowchart of multiply A and B​
    10·1 answer
  • (Correct Answer Recieves Brainliest)
    8·2 answers
  • Date Underline the correct answer from the options. 1. How many basic input devices does a desktop computer have? .. a)2 b)3 c)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!