Write a program to find the Factorial of a number

Showing Answers 1 - 3 of 3 Answers

satish_sudi

  • Jun 25th, 2007
 

Code
  1.  #include<iostream>

  2. using namespace std;

  3. /* factorial function  --recursive*/

  4. int fact(int n){

  5.  if (n == 0)

  6.   return 1;

  7.  n=n*fact(n-1);

  8.  return n;

  9. }

  10. int main() {

  11.  int n=5;

  12.  cout << "Factorial of number " << n << " is : " << fact(n) << endl;

  13.  return 0;

  14. }

Sheenu

  • Sep 27th, 2011
 

//program to find the factorial of a number

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. void main()

  4. {

  5. int a,fact=1;

  6. for(a=1;a<=5;a++)

  7. fact=fact*a;

  8. }

  9. printf("%d",fact);

  10. getch();

  11. }

  Was this answer useful?  Yes

richa

  • Oct 10th, 2012
 

Code
  1. class fact

  2. {

  3. public static void main (String orgs[])

  4. {

  5. int n,fact=1;

  6. for(a=n;a>0;a--)

  7. {

  8. fact=fact*n;

  9. system.out.println("factorial of the no is"+fact);

  10. }

  11. }

  12. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions