Give a recursive algorithm that takes as input two positive integers x and y and returns the product of x and y. The only arithmetic operations your algorithm can perform are addition or subtraction. Furthermore, your algorithm should have no loops.

Answers

Answer 1

Answer:

#include <stdio.h>

int product(int x,int y)

(

 if(y==1)

    return x;

 else

    return (x+product(x,y-1));

)

int main()

(

 int a,b;

 scanf("%d %d",&a,&b);

 printf("%d\n*,product(a,b));

return 0;

)

Explanation:

See above code as explanatory enough.


Related Questions

The formula to convert Fahrenheit (F) temperature to Celsius (C) is C=F-32/1.8 which line of code will accomplish this conversion?

O Celsius = (Fahrenheit - 32) / 1.8

O Celsius = (Fahrenheit - 32) * 1.8

O Celsius = Fahrenheit - 32 * 1.8

O Celsius = Fahrenheit - 32 /* 1.8

Answers

I think it might be the first option

The formula code that coverts the temperature unit of Fahrenheit to Celsius is Celsius = (Fahrenheit - 32) / 18. Therefore, option A is correct.

What are the units of measuring temperature?

Temperature is given as the unit of measuring the hotness or coolness of a body. The SI unit of measuring temperature is Kelvin. The equivalent converts the temperature unit between Kelvin, Celsius, and Fahrenheit.

The code of line that helps in accomplishing the conversion of Fahrenheit to Celsius is,

Celsius = (Fahrenheit - 32) / 18.

Thus, option A is correct.

Learn more about Celsius to Fahrenheit, here:

https://brainly.com/question/14272282

#SPJ2

PEASE ANSWER QUICKLY

What is the value of the variable moneyDue after these lines of code are executed? >>>numSodas = 2 >>>costSodas = 1.50 >>>moneyDue = numSodas * costSodas

The value of moneyDue is ____.

Answers

90
I calculated the sodas

Answer:

3.0

Explanation:

I input 90 and it was not correct, the answer is 3.0 (correct on Edg 2021) :D

3.7) BEST ANSWER BRAINLIEST

your answer will be reported if it is ridiculous


Which is NOT a question that might help a network engineer isolate which layer in a network has a problem?



Is the user operating the software correctly?


Is everything plugged in?


Are messages arriving in a timely manner?


Are the data displaying in a garbled manner?

Answers

Explanation:

i think it is are messages ariving in a timely manner?

Answer:

Is the user operating the software correctly?

Explanation:

Thats the correct one for edge

Write a program to simulate a simple calculator. In your program ask the user to enter an operation selected from the menu, ask for two operands. Calculate the result and display it on the screen. Here is a sample run

Answers

Answer:

Written in Python:

opcode = input("Enter operator: +,-,*,/")

operand1 = float(input("Operand 1: "))

operand2 = float(input("Operand 2: "))

if opcode == "+":

    print(operand1 + operand2)

elif opcode == "-":

    print(operand1 - operand2)

elif opcode == "*":

    print(operand1 * operand2)

elif opcode == "/":

    print(operand1 / operand2)

else:

    print("Invalid Operator")

Explanation:

This prompts user for operator

opcode = input("Enter operator: +,-,*,/")

The next two lines prompt user for two operands

operand1 = float(input("Operand 1: "))

operand2 = float(input("Operand 2: "))

This performs + operation if operator is +

if opcode == "+":

    print(operand1 + operand2)

This performs - operation if operator is -

elif opcode == "-":

    print(operand1 - operand2)

This performs * operation if operator is *

elif opcode == "*":

    print(operand1 * operand2)

This performs / operation if operator is /

elif opcode == "/":

    print(operand1 / operand2)

This displays invailid operator if input operator is not +,-,* or /

else:

    print("Invalid Operator")

Suppose a disk drive has the following characteristics: Six surfaces 16,383 tracks per surface 63 sectors per track 512 bytes/sector Track-to-track seek time of 8.5ms Rotational speed of 7,200rpm a) What is the capacity of the drive

Answers

Answer:

The answer is "2.95 GB"

Explanation:

Given value:

Surfaces = 6

The tracks per surface =16,383

The sectors per track = 63

bytes/sector = 512

Track-to-track seek time = 8.5ms

The Rotational speed = 7,200rpm

[tex]\text{Drive capacity= surface} \times \text{tracks per surface} \times \text{sectors per track} \times \frac{bytes}{sector}[/tex]

                      [tex]= 6 \times 16383 \times 63 \times 512 \\\\= 3170700288 \ B\\\\ = 3023.81543 \ MB \\\\= 2.95294 \ GB\\[/tex]

The drive capacity is 2.95 GB

summarize how to write well-organized paragraphs

Answers

Decide on a controlling idea and create a topic sentence. ...
Explain the controlling idea. ...
Give an example (or multiple examples) ...
Explain the example(s) ...
Complete the paragraph's idea or transition into the next paragraph.

What type of cipher takes one character and replaces it with one character, working one character at a time

Answers

Answer: An algorithm

Explanation: ​An asymmetric encryption key that does have to be protected. ​An algorithm that takes one character and replaces it with one character.

6.24 LAB: Exact change - functions Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is:

Answers

Answer:

Written in Python

money = int(input("Enter Amount Here:  "))

dollar = int(money/100)

money = money % 100

quarter = int(money/25)

money = money % 25

dime = int(money/10)

money = money % 10

nickel = int(money/5)

penny = money % 5

if dollar >= 1:

     if dollar == 1:

           print(str(dollar)+" dollar")

     else:

           print(str(dollar)+" dollars")

if quarter >= 1:

     if quarter == 1:

           print(str(quarter)+" quarter")

     else:

           print(str(quarter)+" quarters")

if dime >= 1:

     if dime == 1:

           print(str(dime)+" dime")

     else:

           print(str(dime)+" dimes")

if nickel >= 1:

     if nickel == 1:

           print(str(nickel)+" nickel")

     else:

           print(str(nickel)+" nickels")

if penny >= 1:

     if penny == 1:

           print(str(penny)+" penny")

     else:

           print(str(penny)+" pennies")

Explanation:

I've added the source code as an attachment where I used comments to explain some lines

Why are computers popular in education these days?

Answers

Answer:

They have unlimited information

Explanation:

Answer:

computers are popular in education these days because students of this generation prefer to learn from mobiles and computers. They can gain lots of extra knowledge than from their book from computers and internet. If they get confused in some problems, they can just search it in Google and get the answer.

What is the output password=sdf345

Answers

Answer:what do you mean

Explanation:

Answer:

False

Explanation:

If you put it in python your answer would be false

Infrastructure as a Service (IaaS) replaces the _________ of the computer hierarchy with an Internet-based infrastructure.A. digital logic level through user levelsB. digital logic level through high-level language levelsC. system software level through high-level language levelsD. digital logic level through machine levels

Answers

Answer:

D. digital logic level through machine levels

Explanation:

In Computer science, the modern computer systems are basically organized in levels and this is known as computer hierarchy. The three levels in a chronological order are operating system level, machine language level and digital (hardware) logic level.

A digital logic level is the most fundamental level of a computer and can be defined as a level of the computer hierarchy which typically comprises of wires and gates. In digital circuits, the two (2) main logic level of the binary logic state are logical low and logical high which is typically denoted by the number 0 and 1 respectively.

In Computer science, the Infrastructure as a Service (IaaS) replaces the digital logic level through machine levels of the computer hierarchy with an Internet-based infrastructure. This is what enables various users to access resources that are available over the internet through the use of cloud storage.

Which is an algorithmic form of a procedure?
A.
function calc_area
B.
area=length*breadth
C.
call function calc_area
D.
return area to the main function
E.
end function calc_area

Answers

Answer:

b

Explanation:

im doing the test right now

Answer:

B is correct!

Explanation:

Which finger types the space bar?

Answers

Answer:

Thumbs

Explanation:

Write a method getIntVal that will get the correct value input as integer numbers from the user. The input will be validated based on the first two numbers received as parameters.

Answers

Complete Question:

Write a method getIntVal that will get the correct value input as integer numbers from the user. The input will be validated based on the first two numbers received as parameters.

In other words, your program will keep asking for a new number until the number that the user inputs is within the range of the <firstParameter> and <secondParameter>.

The method should present a message asking for the value within the range as:

Please enter a number within the range of (<firstParameter> and <secondParameter>):

Note that <firstParameter> should be changed by the value received as that parameter and <secondParameter> as well.

If the user inputs a value that it is lower than the first value, the program will show the message:

The input number is lower than <firstParameter>

Note that <firstParameter> should be changed by the value received as that parameter

If the user inputs a value that it is greater than the first value, the program will show the message:

The input number is greater than <secondParameter>

Note that <secondParameter> should be changed by the value received as that parameter.

You do not need to modify anything in the main method, you just need to write the missing parts of your new getIntVal method.

Answer:

#include<iostream>

using namespace std;

void getIntVal(int num1, int num2) {

int num;

cout<<"Please enter a number within the range of "<<num1<<" and "<<num2<<": ";

cin>>num;

while(num<num1 || num>num2) {

if(num<num1) {

cout<<"The input number is lower than "<<num1<<endl;

}

if(num>num2) {

cout<<"The input number is greater than "<<num2<<endl;

}

cout<<"Please enter a number within the range of "<<num1<<" and "<<num2<<": ";

cin>>num;

}

cout<<"Output: "<<num;

}

int main() {

int num1,num2;

cout<<"Enter lower bound: ";

cin>>num1;

cout<<"Enter upper bound: ";

cin>>num2;

getIntVal(num1, num2);

return 0;

}

Explanation:

Programming Language is not stated, So, I answered using C++

I've added the full source code as an attachment where I use comments to explain difficult lines

Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program.

Answers

import java.util.Arrays;

public class TestScores {

   public static float getAverage(float arr[]){

       float total = 0;

       for (float x : arr){

           if (x < 0 || x > 100){

               throw new IllegalArgumentException();

           }

           else{

               total += x;

           }

           

       }

       return (total / arr.length);

   }

   

   public static void main(String [] args){

       float arr[] = {1,100,0,43,-1};

       System.out.println(getAverage(arr));

   }

}

In the main method we test our getAverage method with the arr array. You can replace the values in the arr array and test your own values. I hope this helps!

The code example of the implementation of the TestScores class in Java is shown below:

What is the class?

java

import java.util.Arrays;

public class TestScores {

   private int[] scores;

   public TestScores(int[] scores) {

       this.scores = scores;

   }

   public double getAverage() {

       int sum = 0;

       for (int score : scores) {

           if (score < 0 || score > 100) {

               throw new IllegalArgumentException("Invalid test score: " + score);

           }

           sum += score;

       }

       return (double) sum / scores.length;

   }

   public static void main(String[] args) {

       int[] scores = {85, 90, 92, 88, 95};

       TestScores testScores = new TestScores(scores);

       try {

           double average = testScores.getAverage();

           System.out.println("Average test score: " + average);

       } catch (IllegalArgumentException e) {

           System.out.println("Error: " + e.getMessage());

       }

   }

}

Read more about  class  here:

https://brainly.com/question/26580965

#SPJ2

The best way to make sure text stand out in eNotes would be to
A. resize it.
B. printit it
C. bold it
D. strike-through​

Answers

The answer is C.Bold it

Answer: (D) bold it.

Explanation:

Write a single statement that prints outsideTemperature with a or - sign. End with newline. Sample output with input 103.5: 103.500000

Answers

Answer:

Written in C Language

#include <stdio.h>

int main() {

   float temp;

   printf("Temperature: ");

   scanf("%f",&temp);

   temp-=(temp + temp);

   printf("%.6f", temp);

    return 0;

}

Explanation:

This line declares temp as float

   float temp;

This line prompts user for input

   printf("Temperature: ");

This line gets user input

   scanf("%f",&temp);

This line negates the user input

   temp-=(temp + temp);

This line prints out the required output with a - sign

   printf("%.6f", temp);

According to Jonathan Zittrain, technology that cannot be modified by the user who wishes to create new uses for it is:_______

a. Sterile
b. Open
c. Generative
d. Clean

Answers

Answer:

a. Sterile

Explanation:

From a lecture that was given by jonathan zittrain, he described a sterile technology as a type of technology that will not develop. And going further he says that a y third party cannot do any sort of coding for such a technology. It works the same way always. He described it in these words 'what you see is what you get'.

is check payable a liability ?​

Answers

Answer:

Yes

Explanation:

Accounts payable (AP) is money owed by a business to its suppliers shown as a liability on a company's balance sheet.

A pay check is a liability

Which are valid variable names? Select 2 options.

cost$

firstNumber

$cost

1stNumber

first_number

Answers

Answer:  

firstNumber

first_number

Explanation: i did it ;)

Answer: firstNumber

Explanation: got it right on edgen

. Because Maya knows that the most important part of an e-mail message is the subject line, she ________.

Answers

Answer:

adjust the subject line if the topic changes after repeated replies

Explanation:

E-mail (electronic mail) message is usually reffered to as a text, usually informal which can be sent electronically or received through a computer network. e-mail message is usually brief but at same time some do contains attachment which allows sending of images as well as spreadsheet. One of the important part of Email message is the Subject Line which serves as the introduction that gives the intent of the message, it is this Subject Line that will show when the recipient is going through the list of emails in his/her inbox. It allows the recipient to know what is conveyed in the body of the message.There are usually action information as well as dates at the end of the email message as well as closing thought.In the case of Maya from the question, Because Maya knows that the most important part of an e-mail message is the subject line, she adjust the subject line if the topic changes after repeated replies, since the subject line convey the information in the body text, so the subject line need to be adjusted to fit the topic as it changes.

Problem1: How Much Snow? Snow is falling at the rate of 0.8 inch per hour. Evaporation occurs at the rate of 2% per hour. Complete program HowMuchSnow.java to calculate how many inches of snow are on the ground after snowing a number of hours.

answer in coding on j creator

Answers

public class HowMuchSnow{

    public static void main(String []args){

       System.out.println("Hello World");

       System.out.println("There are "+ SnowFall(3) + " inches of snow on the ground.");

    }

    public static float SnowFall(float hours){

        float falling = 0.8f - (0.8f * 0.02f);

        return falling * hours;

    }

}

I hope this helps!

Match the correct term from the list below with the correct statement.

Answers

Answer:

self-serving bias

feedback

self-fulfilling prophecy

communication

context

What do type in?
What are the HR tags
What are the h3 headings

Answers

Answer:

HR tags are horizontal breaks in a document.

Your code should look like this:

<html>

<head>

</head>

<body>

<h1>

first heading

</h1>

<h3>

other headings

</h3>

</body>

</html>

<style>

body {

   background-color: #505693;

   color: #FFFFFF;

}

hr {

   background-color: #6A5ACD;

}

</style>

The _________ contains logic for performing a communication function between the peripheral and the bus.

Answers

Answer:

I/O module

Explanation:

The I/o module is known as the input/output module. Such a module is usually connected to system on one end and and in the other end, one or more input/output devices are connected. Such a technique helps to exchange data between the processor and also the input /output device. It helps in information transfer between the internal storage and also the external storage.

Which method accepts a function that combines all the elements in the array and then returns the resulting value?
a. filter()
b. reduce()
c. map()
d. forEach()

Answers

Answer:

The method that accepts a function that combines all the elements in an array and then returns the resulting values is map() method.

Explanation:

map()  method creates a new array with the results of calling a provided  function for every array element. map() element calls function for each array element to compute value.

Computer programmers are responsible for writing code that tells computers commands to follow.

True
False

Answers

True is the correct answer.

Answer:

True

Explanation:

the answer is true

Suppose you discover that you have a directory called bin2, which includes a bunch of useful programs. You want to move those programs into your bin directory, and then delete bin2. What command(s) will you give

Answers

Answer:

The MV command to move the bin2 directory to the bin directory.

Explanation:

Linux operating system uses a hierarchical arrangement of directories to organise information in its system.

It is an open source operating system with various built-in commands and other commands which can be made by a programmer.

The MV command takes a file or directory from a current directory and a destination directory.

Give a recursive algorithm that takes as input two non-negative integers x and y and returns the sum of x and y. The only arithmetic operations your algorithm can perform are Increment(x) which returns x 1 and Decrement(x) which returns x-1. Your algorithm should have no loops.

Answers

Answer:

Following are the code to this question:

Cal_sum(x,y)//defining a recursive method Cal_sum that takes two variable as a parameter

{

if(x==0)// defining If that checks x equal to 0

return y; //return y value

x- 1;//decreasing x value  

y+1;//increasing y value

return Cal_sum(x,y)// calling method recursively

}

Explanation:

In the above-given code, a recursive method "Cal_sum" is declared, that accepts two-variable "x and y" in its parameter, and use if block to checks x is equal to 0 and return the value y variable, and, in the next step, it decreases the value of " x" by "1" and increment the value of y by "1", and call the method "Cal_sum" recursively.

The recursive program which calls itself in a function is used to return the value of y for a given x, y value in the program. The code written in python 3 goes thus :

def calc_sum (x,y) :

#initializes a function named calc_sum which takes in two arguments

if x ==0 :

#checks of the value of x is equal to 0

return y

#it returns y if x == 0

else :

#otherwise

x = x - 1

# decrease the value of x by 1

y = y + 1

#increase the value of y by 1

return calc_sum(x,y)

# calls the function recursively until x ==0

A sample run of the program is given below

print(calc_sum(4, 5 ))

Learn more :https://brainly.com/question/16027903

Write a function, maxRadius, to find the index of the planet with the largest radius in the array. The function should: Be named maxR

Answers

Answer:

The following c code has the maxR function as the calculator of planet radius.

Code:

#include<iostream>

#include<string>

using namespace std;

//if is not asked to import a math library, it can be used the following Pi value.

const double PI = 3.14;

class Planet

{

private:

 string planet;

 double r;

public:

   Planet ()

 {

   this->planet = "";

   this->r = 0.0;

 }

 Planet (string name, double r)

 {

   this->planet = name;

   this->r = r;

 }

 string collectName () const

 {

   return this->planet;

 }

 double collectR () const

 {

   return this->r;

 }

 double collectVolume () const

 {

   return 4 * r * r * r * PI / 3;

 }

};

int

maxR (Planet * planets, int s)

{

 double maxR = 0;

 int index_of_max_r = -1;

 for (int index = 0; index < s; index++)

   {

     if (planets[index].collectR () > maxR)

{

  maxR = planets[index].collectR ();

  index_of_max_r = index;

}

   }

 return index_of_max_r;

}

int

main ()

{

 Planet planets[5];

 planets[0] = Planet ("On A Cob Planet", 1234);

 planets[1] = Planet ("Bird World", 4321);

 int idx = maxR (planets, 2);

 cout << planets[idx].collectName () << endl;

 cout << planets[idx].collectR () << endl;

 cout << planets[idx].collectVolume () << endl;

}

Other Questions
Brian bought 4 yards of fabric. How much is this in feet? -17(y-2) = -17y + 64 mark brainlest if right plz help asapWhat is one of the best ways to decide how to spend your money, time, and energy?A. Always pick the cheapest and fastest thing that is easy to doB. Determine what you value, and focus your resources on thatC. Save as many of your resources as you can for things you likeD. You can only have one important thing in your life at a time Kim bought a hat in California. The hat cost $15 before the 8% sales tax was applied. Howmuch did Kim pay for the hat after taxes were added? Twenty-seven minus of a number (x) is not more than 36. What is the number?A. x > 42B. x -6C. x < 3D. x -6 If a DNA mutation results in the exact same amino acid, it is called a __________ mutation. Funny dialogue between doctor and patient Write an equivalent expression by combining like terms. 3(1/4x+2)+(1/5x2) A car leaves Town A for Town B, which are 550 km apart, at an average speed of72 km/h. At the same time, a truck leaves Town B for Town A and travels alongthe same road as the car at an average speed of 38 km/h. Find the time taken for thetwo vehicles to meet. Then Jorge does inventory on the drinks on average customers consume 22.75 L of lemonade per hour the restaurant is open on Sunday Jorge checks the giant lemonade machine at the start of the weekend there were 346.65 L of lemonade in the machine now there are only 5.4 L left based on this for how many hours was the restaurant open this weekend? Compute the following sums and differences. lol this is super ez Murphy Company sublet a portion of its warehouse for five years at an annual rental of $75,000, beginning on May 1, 2020. The tenant, Sheri Charter, paid one year's rent in advance, which Murphy recorded as a credit to Unearned Rent Revenue. Murphy reports on a calendar-year basis. The adjustment on December 31, 2020 for Murphy should be: INSTRUCTIONS RUN CODE GRADING HISTORY Write code to take a String input from the user, then print the first and last letters of the string on one line. Sample run: Enter a string: surcharge se Protein synthesis is a vital function in all cells. Identify two cell structures involved in protein synthesis and state how each structure functions in protein synthesis. Cell Structure Function in Protein Synthesis Tan, Inc., sold a forklift on April 12, 2020, for $8,000 (its FMV) to its 100% shareholder, Ashley. Tan's adjusted basis for the forklift was $12,000. Ashley's holding period for the forklift: Solid calcium reacts with solid sulfur to produce solid calcium sulfide? Kourtney and her friends baked 120 cupcakes for a bake-sale. Each cupcake is covered with one topping. A. 25B. 115C. 45D. 75How many cupcakes are topped with vanilla frosting?I WILL MAKE YOU BRAINLIEST A pencil is dropped from rest from a height of 1.8 meters above the ground. How much time does it take the pencil to hit the ground? Sales during December were 500 units. The cost of inventory at December 31, Year 1 under the FIFO method would be closest to: