Find elements

Find the product of two numbers in C using recursion

Find the product of two numbers in C using recursion

In this tutorial, we will discuss a concept of  Find the product of two numbers in C using recursion

In this article, we are going to learn  how to Find product of two numbers using recursion in the C  programming language

Find the product of two numbers

Program

This program allows the entry of two digits from the user and to find the product of two numbers using the recursive function in C programming language.

#include <stdio.h>
#include <stdlib.h>

int product(int,int);   //function prototype / declaration
int main()
{
    int num1,num2,result;  //variable declarataion
    printf("Enter two number to find their product\n");
    scanf("%d %d",&num1,&num2);  //numbers receive from the user
    result=product(num1,num2);//assign the output to variable result
    //function call
    printf("PRoduct of %d and %d is %d\n",num1,num2,result);
    getch();
    return 0;
}

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

    }
    else{
        return 0;
    }
}


When the above code is executed, it produces the following results

Enter two numbers to find their product
40
25
Product of 40 and 25 is:1000

 

Method

  • Declare three variables num1, num2 and result as “int” type.
  • Receive two numbers from user and store variable as num1 and num2 respectively.
  • Call the function and assign the output value to variable result.
  • Product() function is used to Calculate the product of of two numbers.
  • Display the result on the screen.

 

Similar post

Calculate the product of two numbers in C++ using recursion

Calculate the product of two numbers in Java using recursion

Calculate the product of two numbers in Python using recursion

 

Suggested for you

Function in C language

Recursion in C language

If statement in C language

Input output function in C language

 

C program to find the sum of natural numbers using recursion
Find product of two numbers using recursion in Python
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

1 month ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

1 month ago