Monday, August 3, 2009

Algorithm to find the factorial value of any number entered through the keyboard using loops?

Algorithm for finding factorial of any number.........steps are





1. Take a number as a input from the user.


2. initialize a variable fact=1





3. fact=fact*number


4. number=number-1


5. repeat step 3 to 5 if number%26gt;0


6. print the value of fact variable

Algorithm to find the factorial value of any number entered through the keyboard using loops?
c++:





int x;


cout%26lt;%26lt;"enter number :";


cin%26gt;%26gt;x;


int factorial=1;


for (int i=x; i %26gt; 0;i--)


factorial =factorial * i;


cout%26lt;%26lt;" facotorial of "%26lt;%26lt;x %26lt;%26lt;" is "%26lt;%26lt;factorial%26lt;%26lt;"\n";


return 0;



tanning

No comments:

Post a Comment