C C++ program to generate table of number using recursion

Coding in C

#include<stdio.h>
void table(int,int,int);
int main()
{
    int num,c=1,res;
    printf("Enter a number: ");
    scanf("%d",&num);
    table(num,c,res);
    return 0;
}
void table(int num, int c, int res)
{
    if(c<=10)
    {
        res=num*c;
        printf("%d\n",res);
        table(num,c+1,res);
    }
}

Coding in C++

#include<iostream>
using namespace std;
void table(int,int,int);
int main()
{
    int num,c=1,res;
    cout<<"Enter a number: ";
    cin>>num;
    table(num,c,res);
    return 0;
}
void table(int num, int c, int res)
{
    if(c<=10)
    {
        res=num*c;
        cout<<res<<endl;
        table(num,c+1,res);
    }
}

Output

C C++ program to generate table of number using recursion

Published by

admin

I am a computer teacher, programmer and web developer