Program in C and C++ to find product of two numbers using recursive function
C Program
#include<stdio.h> int mul(int x, int y){ if(y == 0) return 0; else return (x + mul(x, y -1)); } int main(){ int a, b, m; printf("Enter two numbers :- "); scanf("%d%d", &a, &b); m = mul(a, b); printf("Multiply of %d and %d is %d ", a, b, m); return 0; }
C++ Program
#include<iostream> using namespace std; int mul(int x, int y){ if(y == 0) return 0; else return (x + mul(x, y -1)); } int main(){ int a, b, m; cout<<"Enter two numbers :- "; cin>>a>>b; m = mul(a, b); cout<<"Multiply of "<<a<<" and "<<b<<" is "<<m; return 0; }
Output :-
Related Programs
1.
0 Comments