TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Thursday, 14 May 2020

Recursion In C | Recursion In C Function | Recursion In C In Hindi

Recursion In C



A function that calls itself is known as a recursive function. And, this technique is known as recursion.

What is Recursion?

The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive function.

 

 

image of  Recursion in c function

Fig: Recursion in c

 

Syntax:

void recurse()

{

… …. …

recurse();

… … …

}

int main()

{

… … …

recurse();

… … …

}

 

Program:

#include<stdio.h>

int sum(int n);

int main()

{

int number, result;

printf(“enter a positive integer:”);

scanf(“%d”, &number);

result=sum(number);

printf(“sum =%d”,result);

return 0;

}

int sum(int n)

{

if(n!=0)

return n+sum(n-1);

else

return n;

}

 

Output:

Enter a positive integer : 3

sum=6


No comments:

Post a Comment