using recursion - C Programming
C Program to demonstrate concept of recursion.
/* C Program to demonstrate concept of recursion */
#include <stdio.h>
#include <conio.h>
int add(int pk,int pm);
void main()
{
/* Local definitions */
int k,i,m;
m=20;
k=70;
/* Statements */
clrscr();
i=add(k,m); /* call function */
printf("The value of addition is %d\n",i);
getch();
} /* main */
int add(int pk, int pm)
{
if(pm==0) return (pk);
else return(1+add(pk,pm‒1));
} /* add */
OUTPUT
The value of addition is 90
EXPLANATION: In the program m is assigned 20 and k is assigned 70. The main function calls the sub‒program add(). The subprogram add() executes its body and called itself. Then performs the operation and prints the output.
Computer Programming C Laboratory: Functions C Programs : Tag: C Programming : - C Program to demonstrate concept of recursion