XMPP JavaScript Library

Program to display factorial of a number

Algorithm to display factorial of a number

1 #include <stdio.h>
2 #include <conio.h>
3 void main()
4 {
5 clrscr();
6 long fact=0;
7 printf("Enter a value to find it's factorial");
8 scanf("%ld",&fact);
9 for(int i=(fact-1);i>0;i--)
10 {
11 fact=fact*i;
12 }
13 printf("%ld",fact);
14 getch();
15 }
16
Add Your Comment
   
    Yes! I want to receive all comments by email

  by nithin on 05-May-2012 11:21 pm
but 0!=1...i think d o/p wont be right...
  • Reply
  •  4 Like
  •  4 Dislike
  • Report
  by Nithin MG on 06-May-2012 07:40 pm
my pleasure....
  • Reply
  •  3 Like
  •  2 Dislike
  • Report
  by Sachin Puri on 06-May-2012 12:34 am
Yes you are right,i have't taken care of 0. so now we can include if condition to check if the value scanned is 0 then function will return 1. Thanks for correcting the error
  • Reply
  •  2 Like
  •  2 Dislike
  • Report
  by Megha on 26-Apr-2011 09:29 pm
fact=1;dont u think so..??
  • Reply
  •  4 Like
  •  4 Dislike
  • Report
  by Tom on 30-Apr-2011 09:58 am
It will not make any difference, you can give any value to variable fact, it is just for initialization, because in next line we are asking user to input a value for variable fact so it will over right the value set by us at the time of initialization.
  • Reply
  •  5 Like
  •  4 Dislike
  • Report
  by megha on 30-Apr-2011 10:53 am
yeah.. u r ryt... didnt c that properly..
  • Reply
  •  3 Like
  •  4 Dislike
  • Report
  by Someone on 11-Feb-2011 08:31 am
Thanks for sharing
  • Reply
  •  6 Like
  •  5 Dislike
  • Report

Warning: include(ads/adbrite_300_250.php): failed to open stream: No such file or directory in /home2/sachinpu/public_html/pages/algorithm.php on line 33

Warning: include(ads/adbrite_300_250.php): failed to open stream: No such file or directory in /home2/sachinpu/public_html/pages/algorithm.php on line 33

Warning: include(): Failed opening 'ads/adbrite_300_250.php' for inclusion (include_path='.:/opt/cpanel/ea-php56/root/usr/share/pear') in /home2/sachinpu/public_html/pages/algorithm.php on line 33

About the author

Sachin Puri Hi, I am Sachin Puri, I am a Programmer. Programming is my work and it is the thing i like to do most in my free time.
You can catch Sachin Puri at