Thursday, 26 December 2019

Product of two numbers using Recursion in C

#include<stdio.h>
#include<conio.h>
int mul(int,int);
int main()
{
int a,b,result;
printf("Enter value 1: ");
scanf("%d",&a);
printf("Enter value 2: ");
scanf("%d",&b);
result=mul(a,b);
printf("Product of %d and %d is %d",a,b,result);
getch();
return 0;
}
int mul(int a,int b)
{
if(b==1)
return a;
else
return (mul(a,b-1)+a);
}

No comments:

Post a Comment

Convey your thoughts to authors.