answersLogoWhite

0

In C++:

#include <iostream>

using namespace std;

int fact(int x);

int main()

{

int x, total;

cout << "Enter a number: ";

cin >> x;

total = fact(x);

cout << "The factorial of " << x << " is: " << total << endl;

char wait;

cin >> wait;

return 0;

}

int fact(int x)

{

if(x == 1)

{

return 1;

}

return fact(x - 1) * x;

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Write a C program to find out factorial if 10?

Here's a simple C program to calculate the factorial of 10: #include &lt;stdio.h&gt; int main() { int i; unsigned long long factorial = 1; // Use unsigned long long for larger results for(i = 1; i &lt;= 10; i++) { factorial *= i; } printf(&quot;Factorial of 10 is %llu\n&quot;, factorial); return 0; } This program uses a loop to multiply numbers from 1 to 10 and stores the result in factorial, which is then printed.


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.


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


Write a FORTRAN code to calculating factorials?

Here is a simple FORTRAN code to calculate the factorial of a given non-negative integer: program factorial implicit none integer :: n, result print *, &quot;Enter a non-negative integer:&quot; read *, n result = 1 if (n &lt; 0) then print *, &quot;Factorial is not defined for negative numbers.&quot; else do i = 1, n result = result * i end do print *, &quot;Factorial of&quot;, n, &quot;is&quot;, result end if end program factorial This program prompts the user for an integer, checks if it's non-negative, and then calculates the factorial using a loop.


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.


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; }


Write a C-like program fragment that calculate the factorial function for argment 12 with do while loop?

#!/usr/bin/perl print factorial($ARGV[11]); sub factorial { my($num) = @_; if($num == 1) { return 1; # stop at 1, factorial doesn't multiply times zero } else { return $num * factorial($num - 1); # call factorial function recursively } }


Write the Pseudocode to find the factorial of a number?

Pseudo code+factorial


How do you write a program that calculate factorial in javascript?

factorial number Var num= prompt(&quot;enter any number &quot;); Var i=1; Var fact=1; for(i=1;i


Jntu 2-2 oops through java answers?

write a java program to find factorial using recursive and non recursive


Write a c program to find the factorial of 125?

int main (void) { puts ("18826771768889260997437677024916008575954036487149242588759823150835\ 31563316135988668829328894959231336464054459300577406301619193413805\ 97818883457558547055524326375565007131770880000000000000000000000000\ 000000"); return 0; }


Write a program in Lex to eliminate white space and collect numbers as a token?

write a lex program to delete space from the program