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

Experiment_27_AS

The document outlines an experiment to write a program that calculates the factorial of a number using recursion. It includes an algorithm, code implementation in C, and the expected output. The experiment aims to enhance understanding of recursion and its application in solving mathematical problems.

Uploaded by

Dipanshu Sharma
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)
10 views2 pages

Experiment_27_AS

The document outlines an experiment to write a program that calculates the factorial of a number using recursion. It includes an algorithm, code implementation in C, and the expected output. The experiment aims to enhance understanding of recursion and its application in solving mathematical problems.

Uploaded by

Dipanshu Sharma
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

EXPERIMENT: 27

Objective:
To write a program to ind the factorial of a number using recursion.

Introduction:
This experiment involves using recursion to compute the factorial of a number.

Algorithm:
1. Start the program.

2. Declare a recursive function to calculate factorial.

3. In the main function, take input from the user.

4. Call the recursive function.

5. Print the result.

6. End the program.

Code:
#include <stdio.h>

int factorial(int n) {

if(n == 0)

return 1;

else

return n * factorial(n - 1);

}
f
int main() {

printf(“Name:ARYAN SHUKLA Roll No.:24/B01/043\n");

int num;

printf("Enter a number: ");

scanf("%d", &num);

printf("Factorial of %d is %d", num, factorial(num));

return 0;

Output:

Result:
The program calculates the factorial using recursion.

Learning from Experiment:


Understood recursion and its practical application in mathematical problems.

You might also like