function factorial(n)
{
var x=1;
while(n>1)
x*=(n--);
return x;
}
#!/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 } }
Functions are used to reduce the lines of code and the complexity of the code. For an instance let us suppose that you want to calculate the factorial of numbers at different times in a program. There are two ways to do this 1. Write a 4-5 line code every time you want to calculate factorial. 2. Write a function of 4-5 lines which calculates the factorial and call that function every time you need to calculate factorial by just writing a single line. In C++ you can pass the variable, address of the variable or a reference to the variable in a function
write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)
There isn't much to it:---alert("Hello " + "world!");---'alert' creates a popup, and the + does string concatenation.See related link for a Javascript tutorial.
Pseudo code+factorial
#!/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 } }
/*program to calculate factorial of a number*/ #include<stdio.h> #include<conio.h> void main() { long int n; int a=1; clrscr(); printf("enter the number="); scanf("%ld",&n); while(n>0) { a*=n; n--; } printf("the factorial is %ld",a); getch(); }
1 2 3
Functions are used to reduce the lines of code and the complexity of the code. For an instance let us suppose that you want to calculate the factorial of numbers at different times in a program. There are two ways to do this 1. Write a 4-5 line code every time you want to calculate factorial. 2. Write a function of 4-5 lines which calculates the factorial and call that function every time you need to calculate factorial by just writing a single line. In C++ you can pass the variable, address of the variable or a reference to the variable in a function
int factorial(int n) { int i; int f=1; for(i=2;i<=n;++i) f*=i; return f; }
write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)
There isn't much to it:---alert("Hello " + "world!");---'alert' creates a popup, and the + does string concatenation.See related link for a Javascript tutorial.
JavaScript is a scripting language that is mainly used within a web browser. Jquery is a library of javascript code that can be used together with your javascript program. A set of functions that can preform common tasks is provided, which will reduce the amount of code that you have to write yourself.
Pseudo code+factorial
int main (void) { puts ("18826771768889260997437677024916008575954036487149242588759823150835\ 31563316135988668829328894959231336464054459300577406301619193413805\ 97818883457558547055524326375565007131770880000000000000000000000000\ 000000"); return 0; }
write a java program to find factorial using recursive and non recursive
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.