#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,fact=1;
clrscr();
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("%d",n);
fact=fact*i;
{
printf("the factorial is=%d",fact);
}
getch();
}
By:-Abhishek Goyal(goyal.abhi40@Yahoo.com)
The problem with factorials is that small numbers have huge factorials. Even a 64-bit unsigned int is only capable of storing 20 factorial (denoted 20!). Therefore any factorial function that returns a 64-bit unsigned int must assert for values greater than 20.
The for loop version would be:
UINT64 factorial (UINT64 num)
{
assert (num<21);
UINT64 result = 1;
for(UINT64 n=2; n<=num; result *= n++);
return result;
}
However, a while loop is more efficient as a counter is not required:
UINT64 factorial (UINT64 num)
{
assert (num<21);
UINT64 result = 1;
while (1 < num) result *= num--;
return result;
}
To accommodate factorials greater than 20, you have to create a user-defined class to accommodate the result as there are no built-in types available.
#include int main() { int fact,Factorial; printf("Please Enter Factorial Number\n"); scanf("%d",&fact); Factorial=func_fact(fact); printf("factorial is %d\n",Factorial); } int func_fact(int number) { int i; int factorial=1; for(i=number;i>=1;i--) { factorial=factorial*i; } return 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 } }
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!"); } }
Poor Boy. We do not do your homework here.
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
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")
odd loop means at least the loop execute once.
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) { /*...*/ }