answersLogoWhite

0


Best Answer

/* gcc -ansi -Wall -Wextra -pedantic -s -static 0.c -o 0 */

#include <stdio.h>

int main ( )

{

int n = 5 , factorial = 1 ;

while ( n != 0 )

{

factorial *= n ;

n -- ;

}

printf ( "%i\n" , factorial ) ;

return 0;

}

User Avatar

Wiki User

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

Wiki User

8y ago

Use the following function:

unsigned fact (unsigned num) { return num < 2 ? 1 : num * fact (num-1); }

Note that if sizeof (unsigned) is only 4 (bytes), this function can only handle factorials up to fact (12). However it will easily handle fact (4), returning 4*3*2*1=24.

The non-recursive solution is as follows:

unsigned fact (unsigned num) {

unsigned f = 1;

while (1<num) f *= num--;

return f;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in C to find the factoial of 5?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you give me a program that will compute number 1 to 5?

nr\m;laeoh9y0m g.qthnedxc In fortran: do i=1,5 write(6,*)i enddo stop end This program will write the numbers 1 to 5 on the screen.


Write a program in C to find the complex number of a given number?

There is no such thing; you seem to have misunderstood something.Any real number can be regarded as a complex number with zero imaginary part, eg.: 5 = 5+0i


Using while loop write a program which calculates the product of digits from 1 to 5 and also show these nos vertically?

Using while loop, write a program which calculates the product of digits from 1 to 5 and also show these no's vertically.


Write a program which takes the temperature in farhenheightthe program should display the farhenheight temperature as well as centigrade C equals?

Write a program which takes the temperature in farhenheight.the program should display the farhenheight temperature as well as centigrade. C= (f-32)*5/9


How do you write a program to Multiply 2 numbers?

int i=10, j=5, k; k=i*j; // k = 10 * 5 = 50


Write a program in C for arithmetic operations between two integers your program should guide users with proper message or menu on the console?

Write a program in C for showing working of different logical operator in C.Your program should guide users with proper message/menu on the console. (5 Marks)


How do you find the ratio for 5 over 8?

To find the ratio for 5 over 8, you simply write it as a fraction: 5/8.


How can you write text over image using HTML 5?

It would depend on the program you are using and weather or not it is allowable.


How do you RSA algorithm c?

Perform encryption on the following PT using RSA and find the CT p = 3; q = 11; M = 5


Write a java program to print the following output using the for loop 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5?

12345 1234 123 12 1


How do you write the equal factors to 5 to the 4 power and then find the value?

5 x 5 x 5 x 5 = 625


How do you write a program for triangle pattern 1 3 5 7 5 7 9 11 7 9 11 13?

Use a text-editor.