SlideShare a Scribd company logo
Simple program recursion
simple program finding
factorial
K.LAVANYA
CSE-A
24D21A0535
PPS
RECURSION
• Recursion is a function in
which a function calls itself
• Recursion make large
program into small program
• It has a condition called base
case
• The base which tell a
recursion function where to
stop
Example program for recursion
• #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;
• }
FACTORIAL
• The factorial of a
nonnegative integer
n,written n!(and pronounced
“n factorial”), is the product
• Recursion definition of the
factorial function
• N!=n*(n-1)
• Example
• 5!=5*4*3*2*1
• 5!=5*(4!)
Simple program on factorial
• #include<stdio.h>
• #include<conio.h>
• Int factorial(int);
• Int main()
• {
• Int n;
• Printf(“n enter number”);
• Scanf(“%d”,&n);
• Answer=factorial(n)
• Printf(“factorial=%d”,answer);
• getch()
• Return 0;
• }
• Int factorial(int n)
• {
• Int f;
• If(n==0)
• Return 1;
• Else
• F=n*factorial(n-1);
• Return f;
• }
output
• Enter a number 5
factorial is 120
THANK YOU

More Related Content

PPT
14 recursion
PDF
PyOhio Recursion Slides
PPTX
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
DOCX
Recursion in C
PPT
Lec-6 Recursion of Data Structures & Algorithms
PPTX
RECURSION.pptx
PDF
recursion2
PPT
17recursion
14 recursion
PyOhio Recursion Slides
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
Recursion in C
Lec-6 Recursion of Data Structures & Algorithms
RECURSION.pptx
recursion2
17recursion

Similar to Simple program recursion problem solving.pptx (20)

PDF
12200224070_Adnan_Ahmed_DAAbhbhbh_63.pdf
PDF
[ITP - Lecture 14] Recursion
PDF
Recursion
PPTX
Recursion
PPT
Lec-32 Recursion -Recursion in Computer Science
PDF
25422733 c-programming-and-data-structures-lab-manual
PPT
Lecture9 recursion
PPTX
It is a way of programming or coding technique, in which a function calls it...
PPTX
Looping programs that runs based on conditions
PPTX
newnsnznznxjsjzjjxjsjxhajjzjsjzjsjzjz.pptx
PPTX
pushjfjfjfjkdkjcjdkskjxjjsjdhxjzjzjpita sahu.pptx
PPTX
Lecture09 recursion
PDF
Introduction to Recursion (Python)
PPT
lecture 10 Recursive Function and Macros.ppt
DOCX
Practical write a c program to reverse a given number
DOCX
Practical write a c program to reverse a given number
PPTX
Recursion part 1
PPT
Recursion C programming exercises_ Recursion - w3resource.ppt
PPTX
6 Recursion Using Python 1.pptx6 Recursion Using Python 1.pptx
PPTX
nebnznsnshsjsjsjsjsjssjsjsjsjsjsjsjdjw 2.pptx
12200224070_Adnan_Ahmed_DAAbhbhbh_63.pdf
[ITP - Lecture 14] Recursion
Recursion
Recursion
Lec-32 Recursion -Recursion in Computer Science
25422733 c-programming-and-data-structures-lab-manual
Lecture9 recursion
It is a way of programming or coding technique, in which a function calls it...
Looping programs that runs based on conditions
newnsnznznxjsjzjjxjsjxhajjzjsjzjsjzjz.pptx
pushjfjfjfjkdkjcjdkskjxjjsjdhxjzjzjpita sahu.pptx
Lecture09 recursion
Introduction to Recursion (Python)
lecture 10 Recursive Function and Macros.ppt
Practical write a c program to reverse a given number
Practical write a c program to reverse a given number
Recursion part 1
Recursion C programming exercises_ Recursion - w3resource.ppt
6 Recursion Using Python 1.pptx6 Recursion Using Python 1.pptx
nebnznsnshsjsjsjsjsjssjsjsjsjsjsjsjdjw 2.pptx
Ad

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Structure & Organelles in detailed.
PPTX
Pharma ospi slides which help in ospi learning
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Cell Types and Its function , kingdom of life
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
master seminar digital applications in india
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Structure & Organelles in detailed.
Pharma ospi slides which help in ospi learning
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
102 student loan defaulters named and shamed – Is someone you know on the list?
VCE English Exam - Section C Student Revision Booklet
Cell Types and Its function , kingdom of life
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Anesthesia in Laparoscopic Surgery in India
master seminar digital applications in india
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Ad

Simple program recursion problem solving.pptx

  • 1. Simple program recursion simple program finding factorial K.LAVANYA CSE-A 24D21A0535 PPS
  • 2. RECURSION • Recursion is a function in which a function calls itself • Recursion make large program into small program • It has a condition called base case • The base which tell a recursion function where to stop
  • 3. Example program for recursion • #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; • }
  • 4. FACTORIAL • The factorial of a nonnegative integer n,written n!(and pronounced “n factorial”), is the product • Recursion definition of the factorial function • N!=n*(n-1) • Example • 5!=5*4*3*2*1 • 5!=5*(4!)
  • 5. Simple program on factorial • #include<stdio.h> • #include<conio.h> • Int factorial(int); • Int main() • { • Int n; • Printf(“n enter number”); • Scanf(“%d”,&n); • Answer=factorial(n) • Printf(“factorial=%d”,answer); • getch() • Return 0; • }
  • 6. • Int factorial(int n) • { • Int f; • If(n==0) • Return 1; • Else • F=n*factorial(n-1); • Return f; • }
  • 7. output • Enter a number 5 factorial is 120