#!/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 } }
printf ("x")
// returns n! int fact(final int n) { // keep track of factorial calculation in f // f starts at n, and we will multiply it by all integers less than n int f = n; // loop from n-1 down to 2 for(int i = (n - 1); i > 1; --i) { // increase our total product f *= i; } return f; }
class Abc { public static void main(String[] args) { System.out.println("Hello World!"); } }
then your program will never ends, too unless you pressing the ctrl+c or kill it through your os. can i know the purpose of you creating the loop that never ends? is it just a mistake or are you doing it on purpose?
int factorial(int n) { int i; int f=1; for(i=2;i<=n;++i) f*=i; return f; }
Exactly what do you mean by 'C program in Java'
Wr
Not used
#!/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 } }
take input n chodo
loop: mvi c,59 dcr c mov a,c daa movc,a jnz loop end
odd loop means at least the loop execute once.
to find the factorial we declare a variable n and initialize its value to 1 initiate a loop for example a for loop and multiply the numbers upto 5 code:- for(i=1,n=1;i<=5;i++) { n=n*i; }
printf ("x")
this is a code for calculating it recursivelly: float Factorial (float n) { if (n<=1) return 1.0; else return n* Factorial(n-1); }
int i=0; while (i++<n) { /*...*/ }