answersLogoWhite

0


Best Answer

/*** returns N!, assume N >= 0 ***/

int Factorial(int n) {

if (n <=1 ) /* 0! = 1! = 1 */ return 1;

/** you can place as many know values as you want, like 2!, 3!, etc **/

/** but, recursive call will do just fine, ... **/

return n * Factorial(n - 1); /** compute N * (N-1)! **/

}

User Avatar

Wiki User

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

Wiki User

13y ago

/*mycfiles.wordpress.com Program for Factorial*/

#include<stdio.h>

#include<conio.h>

void main()

{

int n,fact=1;

clrscr();

printf("Enter any Number:\n\n");

scanf("%d",&n);

while(n>1)

{

fact=fact*n;

n-;

}

printf("\nFactorial is=%d",fact);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

factorial of a given number using pointers.

#include<stdio.h>

#include<conio.h>

main()

{

int n, factorial;

printf("\nEnter a number");

scanf("%d", &n);

factcompute(n, &factorial);

printf("\nThe factorial of %d is %d", n, factorial);

}

factcompute(a, b)

int a, *b;

{

int m;

*b = 1;

for (m = 1; m <= a; m++)

*b = *b * m;

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

This program will compute N Factorial for any N, and does not suffer from overflow, because it uses a bin technique and handles each digit individually. For large values of N, you may need to increase your run-time stack size.

/* Portable arbitrary length decimal iterative */

/* one node of a linked list of digits, the first node being low-order */

struct _decimal {

int digit;

struct _decimal *next;

};

typedef struct _decimal decimal;

/* Portable arbitrary length decimal iterative */

/* Initialize the list - necessary on second pass, if main recoded */

void decimal_initialize (decimal *d, int n) {

decimal *next, *nextsave;

d->digit = n;

nextsave = d->next;

d->next = NULL;

next = nextsave;

while (next != NULL) {

nextsave = next->next;

free (next);

next = nextsave;

}

return;

}

/* Portable arbitrary length decimal iterative */

/* Append a digit at the high order position */

void decimal_add_digit (decimal *d, int n) {

decimal *new_digit = (decimal*) malloc (sizeof (decimal));

while (d->next != NULL) d = d->next;

new_digit->digit = n;

new_digit->next = NULL;

d->next = new_digit;

return;

}

/* Portable arbitrary length decimal iterative */

/* Print the digits in reverse order - recursive */

void decimal_print_digits (decimal *d, int last_digit) {

if (d->next != NULL) decimal_print_digits (d->next, false);

printf ("%d", d->digit);

if (last_digit) printf("\n");

return;

}

/* Portable arbitrary length decimal iterative */

/* multiply the list by N */

void decimal_multiply (decimal *d, int N) {

int carry = 0;

while (d != NULL) {

d->digit = d->digit * N + carry;

carry = d->digit / 10;

d->digit %= 10;

if (carry != 0 && d->next 2) {

decimal_initialize (d, 2);

return;

}

while (N > 2) {

decimal_multiply (d, N);

N--;

}

return;

}

/* Example main line */

/* Generates all variations to show differences in results */

int main (int argc, char *argv[]) {

int N;

decimal Decimal = {2, NULL};

if (argc < 2) {

printf ("Enter N (or use command line) : ");

scanf ("%d", &N);

} else {

N = atoi (argv[1]);

}

printf ("Arbitrary: %u! = ", N);

decimal_NFactIterative (&Decimal, N);

decimal_print_digits (&Decimal, true);

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include
#include
void main()
{
int a,b,c=1;
clrscr();
{
printf("enter the number b=");
scanf("%d",&b);
}
for(a=b;a>=1;a--)
c=c*a;
{
printf("the factorial of the num is%d",c);
}
getch();
}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#include<iostream.h>

#include<conio.h>

int fact(int a)

{ int p=1,i;

for(i=1;i<=a;i++)

p*=1;

return (p);

}

void main()

{ int no,p;

cout<<"Enter the number";

cin>>no;

p=fact(no);

cout<<"The Factorial of "<< no <<"is"<<p;

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include<stdio.h>

int factorial(int *);

main()

{

int n,fact;

printf("Enter any integer number you wish to find its factorial\n");

scanf("%d",&n);

fact=factorial(&n);

printf("\n");

printf("The factorial of %d is %d\n",n,fact);

return 0;

}

int factorial(int *num)

{

int i,product=1;

for(i=1;i<=*num;i++)

product*=i;

return product;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include <stdio.h> int main() { int c, n, fact = 1; printf("Enter a number to calculate it's factorial\n"); scanf("%d", &n); for (c = 1; c <= n; c++) fact = fact * c; printf("Factorial of %d = %d\n", n, fact); return 0; }

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

unsigned factorial (unsigned num) {

return num <2 ? 1 : num * factorial (num-1);

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to find factorial of a given number using pointers?
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 write a program to compute and print the factorial of given number using a while loop in c plus plus?

// 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 &gt; 1; --i) { // increase our total product f *= i; } return f; }

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.


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


Program for calculating factorial no using recursion in c?

factorial n is given by formula n! = n.(n-1)....1 int i; long x; x =1; for (i=n;i&gt;1;i--) x = x*i ; will calculate factorial. I have put x as long to avoid integer overflow. checks for n is positive etc. to be added.