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
mixer [17]
3 years ago
5

g write a recursive function that prints out all the even numbers between x and y inclusive if x is odd then the print out will

start at x 1
Computers and Technology
1 answer:
Reil [10]3 years ago
3 0

Answer:

The function written in python is as follows:

def EvenNumbers(x, y):

    if (y < x):

         return

    if (y % 2 == 0):

         EvenNumbers(x, y - 2)

    else:

         EvenNumbers(x, y - 1)

    if (y % 2 == 0):

         print(y)

Explanation:

x represents the lower limit while y represents the upper limit.

So, the recursion will be repeated as long as x <= y

This defines the function

def EvenNumbers(x, y):

This checks if y < x. If yes, the recursion stops execution and return to the main

<em>     if (y < x): </em>

<em>          return </em>

The following if and else condition checks determines the appropriate range of the recursion.

<em>     if (y % 2 == 0): </em>

<em>          EvenNumbers(x, y - 2) </em>

<em>     else: </em>

<em>          EvenNumbers(x, y - 1) </em>

The above takes care of printing starting at x + 1 if x is odd

This checks and prints the even numbers in the range

<em>     if (y % 2 == 0): </em>

<em>          print(y)</em>

<em />

To call the function from main, make use of

EvenNumbers(x, y)

Where x and y are integers

e.g EvenNumbers(2,10), EvenNumbers(1,17), EvenNumbers(3,21)

<em>See attachment</em>

You might be interested in
Program 7 - Circle You write ALL the code, then run it - Produce the correct output. Turn in code and screen print of successful
fgiga [73]

Answer:

Here is the Circle class:

public class Circle {   // class definition

private int radius;    // private data member of type int of class Circle named radius that stores the value of radius

public Circle(int r) {   // parameterized constructor of class Circle that takes radius as argument

 radius = r;  }    // sets value of radius as r

public int getRadius() {   // accessor method to get the value of radius

 return radius;  }   // returns the current value of radius

public int Diameter() {   // method to compute diameter of a circle

 return radius * 2;  }   // multiply radius value by 2 to compute diameter of Circle

 

public double Area() {   // method to compute area of a circle

 return Math.PI  * Math.pow(radius, 2);   }   //the formula of area is

π x radius² where value of π is get using Math.PI

 

 public double Circumference() {   // // method to compute circumference of a circle

 return 2* Math.PI * radius;   }   }  //the formula of circumference is

2 x π x radius where value of π is get using Math.PI

Explanation:

Here is the Main class:

import java.util.Scanner;  //to accept input from user

public class Main {  //definition of Main class

public static void main(String[] args) {  //start of main method

   

    Scanner scanner = new Scanner (System.in);  //creates Scanner object to take input from user

    System.out.println("Enter radius: ");  //prompts user to enter radius

    int r = scanner.nextInt();  //reads the value of radius from user

 Circle c = new Circle(r);  // calls Constructor of Circle passing r as argument to it using the object c of class Circle

 

    if(c.getRadius()<=0){  //calls getRadius method to get current value of radius using objec and checks if this value (input value of r ) is less than or equal to 0

        System.out.println("Error!");   }  //when above if condition evaluates to true then print this Error! message

    else {  //if the value of radius is greater than 0

System.out.println("the radius of this Circle is: " +c.getRadius());  //calls getRadius method to return current value of r (input value by user)

System.out.println("the diameter of this Circle  is: " + c.Diameter());  //calls Diameter method to compute the diameter of Circle and display the result on output screen

System.out.printf("the circumference of this Circle  is: %.2f", c.Circumference());  //calls Circumference method to compute the Circumference of Circle and display the result on output screen

System.out.println();  //prints a line

System.out.printf("the Area of this Circle  is: %.2f", c.Area()); } }  }

//calls Area method to compute the Area of Circle and display the result on output screen

The program and its output is attached.

7 0
3 years ago
Pls awnser I will mark brainliest as soon as possible
german
What are the multiple choice answers?
6 0
3 years ago
Read 2 more answers
For the description below, develop an E-R diagram:
xeze [42]

Answer:

See explaination

Explanation:

E-R diagram:

Entity Relationship Diagram, also known as ERD, ER Diagram or ER model, is a type of structural diagram for use in database design. An ERD contains different symbols and connectors that visualize two important information: The major entities within the system scope, and the inter-relationships among these entities.

Please kindly check attachment for for the ERD of the question asked.

4 0
4 years ago
To change the backround color of a page, which tab would you use?
ivann1987 [24]
I have concluded the answer is a
4 0
3 years ago
Read 2 more answers
Which tab of the ribbon includes the links group for creating hyperlinks or internal references?
Deffense [45]
The correct answer is D.File
5 0
4 years ago
Read 2 more answers
Other questions:
  • "Server Manager will allow you to manage all roles and features installed on any server, and view the status of all your servers
    7·1 answer
  • Select the most likely outcome of making only on-time minimum payments to a credit
    11·1 answer
  • If there are no differences between the amino acid sequences in the cytochrome c protein of humans and chimpanzees why aren't we
    15·1 answer
  • Florida revoked __________ drivers licenses for DUI in a one-year period from 2009 to 2010.
    6·2 answers
  • IT professionals recognize that successful systems must be user-oriented, and users need to be involved, formally or informally,
    11·1 answer
  • Select below the Active Directory server role that provides the functions of Active Directory without the requirements of forest
    14·1 answer
  • Which of the following are characteristics of algorithms? Choose all that apply. They take a step-by-step approach to performing
    12·1 answer
  • New trends, tools, and languages emerge in the field of web technology every day. Discuss the advantages of these trends, tools,
    15·1 answer
  • The valid call to the function installApplication is
    5·1 answer
  • Describe the major elements and issues with system prototyping​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!