C Program to find Product of 2 Numbers using Recursion

Problem: Write a program to accept two numbers and calculate and print the product of two number using recursion.

C Program:
/* Aim: C Program to find Product of 2 Numbers using Recursion */

#include<stdio.h>

int product(int, int);

int main()
{

	int number_1,number_2, result;

	printf("\n Enter two numbers to find their product:- ");
	scanf(" %d%d", &number_1, &number_2);

	result = product(number_1, number_2);

	printf("\n Product of %d and %d is %d \n", number_1, number_2, result);

	return 0;

}

int product(int a, int b)
{

	if(a<b)
	{
		return product(b, a);
	}
	else if(b != 0)
	{
		return (a + product(a, b - 1));
	}
	else
	{
		return 0;
	}
}

/* Output of above code:-

Enter two numbers to find their product:- 110 240
Product of 110 and 240 is 26400

*/
Get This Program: