Saturday, 25 February 2012

Print table of a desired number with Recursion

#include<iostream>
using namespace std;

int table (int number , int n); // prototype

int main(){

int number ;
cout<<"Please enter Number for which you want to print table : ";
cin>>number;
table(number , 10); // function calling and passing number and
//numbers of multiples(in this case up to 10th
// multiple)

return 0;}

int table (int number , int n){

if(n == 1)
{
cout<<number<<" * "<<n<< " = "<<number*n<<endl;
return 1;
}
table(number , n-1); // recursive calling
cout<<number<<" * "<<n<< " = "<<number*n<<endl;

return 1;
}

<by m.ali>

No comments:

Post a Comment