C# Program to Find Product of 2 Numbers Using Recursion Last Updated : 19 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Given two numbers x and y find the product using recursion. Recursion is a process in which a function calls itself directly or indirectly and the corresponding function is known as a recursive function. It is used to solve problems easily like in this article using recursion we will find the product of two numbers. Examples: Input : x = 10, y = 3 Output : 30 Input : x = 70, y = 4 Output : 280 Approach: To print the product of two number using recursion follow the following steps: For our task we have two numbers, i.e., x, y.Initialize a variable result with value zero.Recursively add the x to result for y times.Take the base condition as y == 0. When y is equal to 0 then return from function.At The end of iteration the result variable will contain the product of x, y. Example: C# // C# program to display the product of // two numbers using Recursion using System; class GFG{ // Recursive function for calculating // product of two numbers. static int product(int x, int y) { // If y is equal to zero then return 0 if (y == 0) return 0; // Recursively calculate // y times sum of x else return (x + product(x, y - 1)); } // Driver code public static void Main () { int x = 10, y = 3; Console.Write(product(x, y)); } } Output30 We can optimize this code by swapping the x and y if y is greater than x. Lets us assume that x = 3 and y = 150 if we follow the above program then the x is added recursively 150 times, but by swapping x,y (i.e. x = 150, y = 3) we only need to add x recursively 3 times. C# // C# program to display the product of // two numbers using Recursion using System; class GFG{ // Recursive function for calculating // product of two numbers. static int product(int x, int y) { // If y is equal to zero then return 0 if (y == 0) return 0; // Recursively calculate // y times sum of x else return(x + product(x, y - 1)); } // Driver code public static void Main() { int x = 3, y = 150; // Swapping the x and y if the y > x. if (x < y) Console.Write(product(y, x)); else Console.Write(product(x, y)); } } Output450 Comment More infoAdvertise with us Next Article C++ Program to Find Factorial Using Recursion P pulamolusaimohan Follow Improve Article Tags : C# CSharp-programs Similar Reads Shell Program to Calculate the Factorial of a Number Here we are going to see to calculate the factorial of a number. Factorial of a non-negative integer is the multiplication of all integers smaller than or equal to n. For example factorial of 5 is 5*4*3*2*1 which is 120. Method 1: Using Recursive Factorial can be calculated using the following recur 2 min read Maximum Product Subarray in C In this article, we will learn how to find the product of the maximum product subarray for a given array that contains both positive and negative integers,Example:Input: arr[] = [2, 3, -2, 4]Output: 6Explanation: [2, 3] has the largest product 6.Table of ContentMethod 1: Traversing Over Every Subarr 6 min read C Program to Find Sum of Natural Numbers using Recursion Natural numbers include all positive integers from 1 to infinity. There are multiple methods to find the sum of natural numbers and here, we will see how to find the sum of natural numbers using recursion. Example Input : 5Output : 15Explanation : 1 + 2 + 3 + 4 + 5 = 15 Input : 10Output : 55Explanat 2 min read C++ Program to Find Factorial Using Recursion The factorial of a number is denoted by "n!" and it is the product of all positive integers less than or equal to n. In this article, we will learn how to find the factorial of a number using recursion in C++. Example Input: 5 Output: Factorial of 5 is 120 Factorial Using Recursion in C++The Factori 2 min read C++ Program to Find Factorial of a Number Using Iteration Factorial of a number n is the product of all integers from 1 to n. In this article, we will learn how to find the factorial of a number using iteration in C++. Example Input: 5Output: Factorial of 5 is 120Factorial of Number Using Iteration in C++To find the factorial of a given number we can use l 2 min read C++ Program To Multiply Two Floating-Point Numbers Here, we will see how to multiply two floating-point numbers using the C++ program. Floating point numbers are numbers that include both integer part and fractional parts represented in the form of decimal and exponential values. float data type is used to store floating point values. For example In 2 min read Like