Write an algorithm to find the product of two numbers
Answers
Answered by
14
- ➡️➡️One simple way is to add x , y times OR add y, x times which is simple enough and is linear.⬅️⬅️
- ➡️➡️Second way is to pick any number(say x) and see which all bits are set in that number and if ith bit is set just do this: product +=y<<i//product is 0 initially and do this for all i.⬅️⬅️
hope it's help you ✔️✔️
Answered by
9
Answer:
Written in Java:
import java.util.Scanner;
class HelloWorld {
public static void main(String[] args) {
// Creates a reader instance which takes
// input from standard input - keyboard
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = reader.nextInt();
System.out.println("Enter another number: ");
int number2 = reader.nextInt();
int result = number*number2;
System.out.println(result);
}
}
Explanation:
If u want it in another language, just let me know :).
Similar questions
Math,
4 months ago
Computer Science,
4 months ago
Computer Science,
4 months ago
Physics,
10 months ago
English,
10 months ago
Science,
1 year ago
English,
1 year ago