Search This Blog


Thursday, 18 April 2019

C Program to Find Product of 2 Numbers using Recursion

Welcome back to codejunction.in , Great to see you guyz again on our blogs but make sure to check out our latest blogs for more knowledge.


This is a C program to find product of 2 numbers using recursion.

This C program using recursion, finds the product of 2 numbers without using the multiplication operator.

CODE


#include<stdio.h>

int multiply(int,int);

int main(){

    int a,b,product;
    printf("Enter any two integers: ");
    scanf("%d%d",&a,&b);

    product = multiply(a,b);

    printf("Multiplication of two integers is %d",product);

    return 0;
}

int multiply(int a,int b){

    static int product=0,i=0;

    if(i < a){
         product = product + b;
         i++;
         multiply(a,b);
    }

    return product;
}








OUTPUT


No comments:

Post a Comment