Monday, May 24, 2010

Factorial Program using c++?

Need a program using loop (not if and else)





Need this badly...





Option ! (Factorial)


1. Prompt the user to enter an integer


2. Accept the integer value n


3. Let the integer value a = 1


4. Let a = a * n


5. Let n = n - 1


6. Repeat 4 - 5 while n %26gt; 0


7 display a





I am really not that good in programming so please help with the formula and conditions for the code....please include scanf and printf...

Factorial Program using c++?
try this one:





http://www.cprogramming.com/
Reply:The description is recursive; if/else is implied, what are you asking? How to use :? or while loop or what?
Reply:void main()


{


int n,a,fact=1 ;





printf("Enter the value of number ");


scanf("%d",%26amp;n);





while(n!=0)


{


fact=fact*n;


n=n-1;


}


printf("Factorial of %d is %d",n,fact);


getch();


}








use cout and cin in place of printf and scanf ,,,,,,,if u want then i can also do that


No comments:

Post a Comment