0% found this document useful (0 votes)
12 views2 pages

Lab CSE 304-02

The report details the implementation of a factorial calculation program in C++ using a user-defined recursive function. It includes the algorithm, pseudocode, and source code, demonstrating the concept of recursion and its application in programming. The conclusion highlights the enhanced understanding of recursion and C++ programming concepts gained through the experiment.

Uploaded by

mecaf52858
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Lab CSE 304-02

The report details the implementation of a factorial calculation program in C++ using a user-defined recursive function. It includes the algorithm, pseudocode, and source code, demonstrating the concept of recursion and its application in programming. The conclusion highlights the enhanced understanding of recursion and C++ programming concepts gained through the experiment.

Uploaded by

mecaf52858
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Dhaka International University

Department of Computer Science and Engineering


Report no: 02 Date of submission: 30 January, 2025

Report title: Implementation of factorial calculation using user-defined recursive function in


C++ programming language.

IDE: Visual Studio Code.

Algorithm: Algorithm of adding two numbers using user define function is given below:
Step-1: start
Step-2: Input- Take an integer n as input from the user.
Step-3: Define a Recursive Function factorial(n):
• If n == 1, return 1 (base case).
• Otherwise, return n * factorial(n - 1).
Step-4: Call the factorial() function with the input n and store the result.
Step-5: Output- Print the result.
Step-6: End the program.

Pseudocode:

1. Start
2. Input the number n
3. Define function factorial(n):
• If n == 1, return 1
• Else, return n * factorial(n - 1)
4. Call factorial(n) and store the result in result
5. Print result
6. End

Source code:
#include<bits/stdc++.h>
using namespace std;
int factorial(int n){
if(n==1){
return 1;
}
return n*factorial(n-1);
}
int main(){
int n;
cout<<"Enter the number: ";
cin>>n;
cout<<"Factorial of "<<n<<" is: "<<factorial(n)<<endl;
return 0;
}

1 | Page Batch no:D-80 (1st Shift) Roll No: 30


Dhaka International University
Department of Computer Science and Engineering

Output: Output of the program is given below:

Conclusion:
In this lab report, we successfully implemented a program in C++ to calculate the factorial of
a number using a user-defined recursive function. The program demonstrates the use of
recursion, where a function calls itself to solve a problem. By utilizing the base case (n == 1),
we were able to terminate the recursion and compute the factorial for any positive integer input.
This lab enhanced our understanding of recursion and how it can be used to solve problems
efficiently in programming. Overall, the experiment strengthened our knowledge of recursive
functions, basic input/output handling, and C++ programming concepts.

2 | Page Batch no:D-80 (1st Shift) Roll No: 30

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy