Question

In: Computer Science

Guided Assignment Problem 1: Multiplication Review the Three-Question Approach used to verify the Factorial recursive algorithm...

Guided Assignment Problem 1: Multiplication

Review the Three-Question Approach used to verify the Factorial recursive algorithm in Ch. 3.2.

Your Tasks:

  1. Now we need to develop a recursive algorithm for multiplication operation with two positive integers without using the multiplication operator. Your answer should be in pseudocode or Java code format.
  2. Then use the Three-Question Approach to verify your recursive algorithm. No coding is required for this assignment.

    Recursive method header given as: int multiplication (int a, int b)

    Hints

  3. a multiply b is to the same is b + (a -1) multiply b, in terms of recursion, the problem is simplified. The process keeps going until base case is reached, which is 1*b = b.
  4. randerson112358. (2015, Feburuary 13). Recursion function to multiply two positive integers. [Video file, Length 5:13].
  5. Please include the following in the Word document you created for the assignment for the final submission:
    • Your responses to the two tasks listed above

Solutions

Expert Solution

Code:

Code:

import java.util.Scanner;

public class Main {

// this method takes two arguments
// calculates multiplication recursive approach
// return the final result
   static int multiplication (int a, int b) {
      
//        check if the value of a is >0
// if it is greater then again call the multiplication function
       if(a>0) {
           return b + multiplication(a-1, b);
       }
      
//        else return 0
       else {
           return 0;
       }
      
   }
   public static void main(String[] args) {
      
//    declate two variables a and b
   int a,b;
  
//    create an object for scanner class
   Scanner in = new Scanner(System.in);
  
//    read the input from the user
System.out.print("Enter a value: ");
   a = in.nextInt();
  
   System.out.print("Enter b value: ");
   b = in.nextInt();
  
//    output the result by calling the multiplication(a,b)
   System.out.println(multiplication(a, b));
  
   }

}


Related Solutions

Problem 1: Recursive anagram finder please used Java please Write a program that will take a...
Problem 1: Recursive anagram finder please used Java please Write a program that will take a word and print out every combination of letters in that word. For example, "sam" would print out sam, sma, asm, ams, mas, msa (the ordering doesn't matter) input: cram output: cram crma carm camr cmra cmar rcam rcma racm ramc rmca rmac acrm acmr arcm armc amcr amrc mcra mcar mrca mrac macr marc Hints: Your recursive function should have no return value and...
1. For this question, you will review a process, identify problem areas ( such as wastes,...
1. For this question, you will review a process, identify problem areas ( such as wastes, cycle time inefficiencies, etc), and suggest an improved process. Open and read the Process Improvement (Final Q 1) document which describes the process steps in words and also includes a process map as a visual tool for understanding what's going on in each step. You will need to respond to the following three subquestions: a. Of the 9 process steps in the Process Improvement...
ACC161 Unit 2 Review Assignment 1. Define the term liabilities. 2. What are the three crucial...
ACC161 Unit 2 Review Assignment 1. Define the term liabilities. 2. What are the three crucial factors/characteristics of liabilities? 3. What are known liabilities? Give four examples of known liabilities. 4. What is capital stock? 5. Which financial statement will you find the stocks listed for a corporation? 6. What is the difference between common stock and preferred stock? 7. What is the difference between "authorized stock" and "issued and outstanding stock"? 8. What is the difference between par value...
Question 1 The flow-to-equity approach has been used by the firm to value their capital budgeting...
Question 1 The flow-to-equity approach has been used by the firm to value their capital budgeting projects. The total investment cost at time 0 is $640,000. The company uses the flow-to-equity approach because they maintain a target debt to value ratio over project lives. The company has a debt to equity ratio of 0.5. The present value of the project including debt financing is $810,994. What is the relevant initial investment cost to use in determining the value of the...
Assignment I Question 1: Prepare a report explaining ITS technologies used in transport sector in Japan,...
Assignment I Question 1: Prepare a report explaining ITS technologies used in transport sector in Japan, Europe and USA (in 2000 words). Question 2: How you can apply ITS technologies to improve transportation situation in USA (in 500 Words)? Question 3: How TSM and TDM are used to reduce traffic problems in Japan, China, Europe and Singapore (in 1000 words)? Question 4: How Bus Rapid Transit (BRT) is used in Bogota and Curitiba to solve transport problems (in 1000 words)?
CPSC 1103 Assignment 1 Problem A cell phone provider has three different subscription packages for its...
CPSC 1103 Assignment 1 Problem A cell phone provider has three different subscription packages for its customers: Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour. Package B: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour. Package C: For $19.95 per unlimited access is provided. Write a program to ask which package the customer has purchased, what month they are using, and how...
Assignment Question(s): Part-1 1.   Define motivation and explain three motivational theory from the chapter. What kinds...
Assignment Question(s): Part-1 1.   Define motivation and explain three motivational theory from the chapter. What kinds of needs motivate employees? Is a good reward good enough? How do other factors affect motivation? 2.   What are the types of incentives I might use to influence employee behaviour? How can I use compensation and other rewards to motivate people? Use at least 3 scientific references to support your answers. Follow APA-style when referencing. Part-2 Students sometime report negative experiences when working with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT