Wednesday, February 13, 2013

C Language Example # 16 Loop Example : Recursion : Calling of function itself from its body

C Language Example # 16 Loop Example : Recursion : Calling of function itself from its body.

Lets now starts with Advance concept of Looping Structure of C Programming Language.

//Written by Latest Technology Guide    
//Title : C Language Example # 16 Loop Example : Recursion : Calling of function itself from its body.
  
#include <stdio.h>
#include <conio.h>

void main()
{
clrscr();
int n;

void series(int,int);

printf("How Many Elements are there :  ");
scanf("%d",&n);

series(1,n);

getch();

}
void series(int start,int n)
{


if(start>n)
return;
else
{
printf("%3d",start);
}
series(start+1,n);
}

Output:
Suppose we assume that you have entered value of N : 5
then output of program will be as follow:
1 2 3 4 5
--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 16 Loop Example : Recursion : Calling of function itself from its body...

* Enter Value of N and you will find the series as shown in the output..

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

No comments:

Post a Comment