Nog Shine
0
Q:

recursive in c++

//AUTHOR:praveen
//Function calling itself 
//Example in c++
#include<iostream>
using namespace std;
int recursion(int a){
  	if(a==1)//BASE CASE
      return 0;
	cout<<a;
  	a=a-1;
  	return recursion(a);//FUNCTION CALLING ITSELF
}
int main(){
  	int a=5; 
	recursion(a);
  	return 0;
}
//OUTPUT: 5 4 3 2 
0
// A C++ program to demonstrate working of 
// recursion 
#include<bits/stdc++.h> 
using namespace std; 
  
void printFun(int test) 
{ 
    if (test < 1) 
        return; 
    else
    { 
        cout << test << " "; 
        printFun(test-1);    // statement 2 
        cout << test << " "; 
        return; 
    } 
} 
  
int main() 
{ 
    int test = 3; 
    printFun(test); 
} 
0

New to Communities?

Join the community