answersLogoWhite

0

/*program to find the factorial of a given number*/

#include<stdio.h>

#include<conio.h>

int fact(int);

void main()

{

int n,c;

printf("\n enter the number for which you want to find the factorial");

scanf("%d",&n);

c=fact(n);

printf("\n the factorial of the number %d is %d",n,fact);

getch();

}

int fact(int n)

{

int k;

if(n==0)

return(1);

else

k=n*fact(n-1);

return(k);

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Math & Arithmetic

A program for simple factorial in prolog?

In Prolog, a simple factorial program can be defined using recursion. Here's a basic implementation: factorial(0, 1). % Base case: factorial of 0 is 1 factorial(N, Result) :- N &gt; 0, N1 is N - 1, factorial(N1, Result1), Result is N * Result1. % Recursive case You can query the factorial of a number by calling factorial(N, Result). where N is the number you want to compute the factorial for.


Program for finding the factorial of the two given number using constructor?

kjhk


output of a c program using function to find factorial of a number?

In a C program that calculates the factorial of a number using a function, the program typically prompts the user for an integer input. The function then recursively or iteratively computes the factorial by multiplying the number by the factorial of the number minus one until it reaches one. For example, if the user inputs 5, the program outputs 120, as 5! = 5 × 4 × 3 × 2 × 1. The final result is displayed on the screen.


How do you make a programm to find the fectorial by using fuction?

To create a program that calculates the factorial of a number using a function, you can define a recursive function or use an iterative approach. For example, in Python, you can define a function factorial(n) that returns 1 if n is 0 or 1, and calls itself with n-1 otherwise. Alternatively, you can use a loop to multiply the numbers from 1 to n. Here's a simple example using recursion: def factorial(n): if n == 0 or n == 1: return 1 else: return n * factorial(n - 1)


7 Write a C program to compute the factorial of a number using for loop?

int factorial(int n) { int i; int f=1; for(i=2;i&lt;=n;++i) f*=i; return f; }

Related Questions

A program for simple factorial in prolog?

In Prolog, a simple factorial program can be defined using recursion. Here's a basic implementation: factorial(0, 1). % Base case: factorial of 0 is 1 factorial(N, Result) :- N &gt; 0, N1 is N - 1, factorial(N1, Result1), Result is N * Result1. % Recursive case You can query the factorial of a number by calling factorial(N, Result). where N is the number you want to compute the factorial for.


What is a Flow chart for finding factorial of a given number using recursion function?

no answer....pls post


Program for finding the factorial of the two given number using constructor?

kjhk


Program to find factorial of a number using inheritance?

/*71.PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; int fact(int); void main() { int n,f; clrscr(); printf("Enter number whose factorial is to be calculated: "); scanf("%d",&amp;n); if(n&gt;0) { f=fact(n); printf("factorial of %d is %d",n,f); } else printf("Factorial of numbers less than 1 does not exist"); getch(); } int fact(int n) { int facto=1; if(n&gt;1) facto=n*fact(n-1); else return 1; return(facto); }


output of a c program using function to find factorial of a number?

In a C program that calculates the factorial of a number using a function, the program typically prompts the user for an integer input. The function then recursively or iteratively computes the factorial by multiplying the number by the factorial of the number minus one until it reaches one. For example, if the user inputs 5, the program outputs 120, as 5! = 5 × 4 × 3 × 2 × 1. The final result is displayed on the screen.


Write a java program to find the factorial of a given number?

Here's a simple Java program to find the factorial of a given number using a recursive method: import java.util.Scanner; public class Factorial { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print(&quot;Enter a number: &quot;); int number = scanner.nextInt(); System.out.println(&quot;Factorial of &quot; + number + &quot; is &quot; + factorial(number)); } static int factorial(int n) { return (n == 0) ? 1 : n * factorial(n - 1); } } This program prompts the user for a number and calculates its factorial recursively.


What is the algorithm n flowchart for calculating factorial of number using recursion?

A flowchart for factorial of number can be made using different software's. Microsoft Word is the most popular software for beginners to make simple flowcharts.In order to draw the flowchart write the number at the top of the paper and then draw two lines under it going slightly to the sides. Decide what two numbers can be multiplied to equal that number. Keep going until you can no longer get to smaller numbers.


Program for calculating factorial no using recursion in c?

factorial n is given by formula n! = n.(n-1)....1 int i; long x; x =1; for (i=n;i&gt;1;i--) x = x*i ; will calculate factorial. I have put x as long to avoid integer overflow. checks for n is positive etc. to be added.


How do you make a programm to find the fectorial by using fuction?

To create a program that calculates the factorial of a number using a function, you can define a recursive function or use an iterative approach. For example, in Python, you can define a function factorial(n) that returns 1 if n is 0 or 1, and calls itself with n-1 otherwise. Alternatively, you can use a loop to multiply the numbers from 1 to n. Here's a simple example using recursion: def factorial(n): if n == 0 or n == 1: return 1 else: return n * factorial(n - 1)


What is the C program for heap sort using recursion?

123


What is the most efficient way to implement a factorial algorithm in a programming language?

The most efficient way to implement a factorial algorithm in a programming language is to use an iterative approach rather than a recursive one. This involves using a loop to multiply the numbers from 1 to the given input number to calculate the factorial. This method is more memory-efficient and faster than using recursion.


How do you write a program to factorial in PHP?

To write a program that calculates the factorial of a number in PHP, you can use a recursive function or an iterative approach. Here’s a simple example using a loop: function factorial($n) { $result = 1; for ($i = 2; $i &lt;= $n; $i++) { $result *= $i; } return $result; } echo factorial(5); // Outputs: 120 This code defines a function that multiplies numbers from 2 up to the given number $n to compute the factorial.