answersLogoWhite

0


Best Answer

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

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#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();

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

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

}

}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

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

This answer is:
User Avatar

User Avatar

Wiki User

13y ago
Program to calculate factorial using while loop in c

#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();

}

-Shruti Jain
This answer is:
User Avatar

User Avatar

Wiki User

16y ago

double Factorial(int i)

{

double x = 1;

if (i <= 1)

return 1;

do

{

x *= i--;

} while (i > 0);

return x;

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

unsigned __int64 factorial(unsigned __int64 number)

{

unsigned __int64 factorial=1;

while(number)

factorial*=number--;

return(factorial);

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

In Java (not tested): long factorial(int number) { long result = 1; for (int i = 1; i

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program to compute and print the factorial of given number using a while loop in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Programming to calculate a factorial number?

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


How do find factorial using vbscript?

&lt;html&gt; &lt;script language="vbscript"&gt; n=cint(inputbox("Enter a number")) dim f f=1 if n&lt;0 then Msgbox "Invalid number" elseif n=0 or n=1 then MsgBox "The factorial of given number "&amp;n&amp;" is :"&amp;f else for i=n to 2 step -1 f=f*i next MsgBox "The factorial of given number "&amp;n&amp;" is :"&amp;f end if &lt;/script&gt; &lt;/html&gt;


Write an algorithm to print the factorial of given number and then draw the flowchart?

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).


What is a recursive function?

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 &gt; 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.


How do you find greatest factor of a number which is a factorial number in c language?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; main() { int f=1,i=1,n; clrscr(); printf("\n Enter factorial value"); scanf("%d",&amp;n); for(;i&lt;=n;i++) { f=f*i; } printf("\n The factorial value=%d",f); getch(); }

Related questions

Program for finding the factorial of the two given number using constructor?

kjhk


How do you find factorial of given number?

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 number using recursion?

/*program to find the factorial of a given number*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; int fact(int); void main() { int n,c; printf("\n enter the number for which you want to find the factorial"); scanf("%d",&amp;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); }


Find flow chart for factorial of given number?

i need a pic of cuson


Programming to calculate a factorial number?

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


How many keywords are there in c?

answer:32 programme to print factorial of a given number in c languages


What is a Flow chart for finding factorial of a given number using recursion function?

no answer....pls post


How many diagonals do hexagons have?

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 is the age of a Colt revolver serial number dT9T22?

What Colt model? Serial number given, dT9T22 does not compute.


How do find factorial using vbscript?

&lt;html&gt; &lt;script language="vbscript"&gt; n=cint(inputbox("Enter a number")) dim f f=1 if n&lt;0 then Msgbox "Invalid number" elseif n=0 or n=1 then MsgBox "The factorial of given number "&amp;n&amp;" is :"&amp;f else for i=n to 2 step -1 f=f*i next MsgBox "The factorial of given number "&amp;n&amp;" is :"&amp;f end if &lt;/script&gt; &lt;/html&gt;


Write an algorithm to print the factorial of given number and then draw the flowchart?

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).


Flowchart to find factorial of a given no?

Kat