// 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;
}
#include
#include
void main()
{
int n,i,fact=1;
clrscr();
printf("enter the value of n:");
Scanf("%d",&n);
for(i=1;i<=n;i++)
fact=fact*i;
printf("%the factorial of n%d is %d ",n,fact);
getch();
}
import java.util.*;
public class fact2
{
public static void main(String[] args)
{
Scanner kbd = new Scanner(System.in);
System.out.println("Enter any number");
int num = kbd.nextInt();
int temp=1,fact=1;
while(temp<=num )
{
fact = fact* temp;
temp++;
}
System.out.println("The factorial is:" +fact);
}
}
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.
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.
echo factorial of a number
echo Enter the number
read n
i=1
fact=1
while test $i -le $n
do
fact=`expr $fact \* $i`
i=`expr $i + 1`
done
echo The factorial of a number is $fact
#include
#include
void main()
{
int i,fact=1,a;
printf("enter the num whose factorial u want to take out");
scanf("%d",&a);
i=a;
while(i>0)
{
fact=fact*i;
i--;
}
printf("factorial=%d",fact);
getch();
}
Program to calculate factorial using while loop in c++#include
#include
void main()
{
int i,fact=1,a;
cout<<"enter the num whose factorial u want to take out";
cin>>a;
i=a;
while(i>0)
{
fact=fact*i;
i--;
}
cout<<"factorial="< getch(); }
double Factorial(int i)
{
double x = 1;
if (i <= 1)
return 1;
do
{
x *= i--;
} while (i > 0);
return x;
}
unsigned __int64 factorial(unsigned __int64 number)
{
unsigned __int64 factorial=1;
while(number)
factorial*=number--;
return(factorial);
}
In Java (not tested): long factorial(int number) { long result = 1; for (int i = 1; i
double factorial(double N){double total = 1;while (N > 1){total *= N;N--;}return total; // We are returning the value in variable title total//return factorial;}int main(){double myNumber = 0;cout > myNumber;cout
<html> <script language="vbscript"> n=cint(inputbox("Enter a number")) dim f f=1 if n<0 then Msgbox "Invalid number" elseif n=0 or n=1 then MsgBox "The factorial of given number "&n&" is :"&f else for i=n to 2 step -1 f=f*i next MsgBox "The factorial of given number "&n&" is :"&f end if </script> </html>
write an algorithm to print the factorial of a given number and then draw the flowchart. This looks like someones homework, defiantly someone looking for the easy way. When it comes to programming, the more you do the better you get. Experience counts (making your own mistakes and learning from the mistake).
A recursive function is one that calls upon itself until a given result in the original call is met. Take a look at this example. Program Recursion; Uses crt; Var number:longint; Function Factorial(number:longint):longint; Begin if number > 0 then factorial:=number*factorial(number-1) else factorial:=1; End; Begin clrscr; readln(number); writeln(factorial(number)); readln; End. Note how the function factorial calls itself.
#include<stdio.h> #include<conio.h> main() { int f=1,i=1,n; clrscr(); printf("\n Enter factorial value"); scanf("%d",&n); for(;i<=n;i++) { f=f*i; } printf("\n The factorial value=%d",f); getch(); }
kjhk
Factorials are the product of 1 and all the integers up to the given number. Simply put, 5 factorial or 5! = 5*4*3*2*1
/*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); }
i need a pic of cuson
double factorial(double N){double total = 1;while (N > 1){total *= N;N--;}return total; // We are returning the value in variable title total//return factorial;}int main(){double myNumber = 0;cout > myNumber;cout
answer:32 programme to print factorial of a given number in c languages
no answer....pls post
The number of diagonals in an n-sided polygon is given by nC2 - n (where n is the number of sides of the polygon) or in the expanded form: factorial (n) _______________________ {factorial (2) * factorial (n-2)} substituting (n = 6) for a hexagon we get the number of diagonals as 9. Similarly, substituting (n=5) for a pentagon we get the number of diagonals as 5.
What Colt model? Serial number given, dT9T22 does not compute.
<html> <script language="vbscript"> n=cint(inputbox("Enter a number")) dim f f=1 if n<0 then Msgbox "Invalid number" elseif n=0 or n=1 then MsgBox "The factorial of given number "&n&" is :"&f else for i=n to 2 step -1 f=f*i next MsgBox "The factorial of given number "&n&" is :"&f end if </script> </html>
write an algorithm to print the factorial of a given number and then draw the flowchart. This looks like someones homework, defiantly someone looking for the easy way. When it comes to programming, the more you do the better you get. Experience counts (making your own mistakes and learning from the mistake).
Kat