#### Archived

This topic is now archived and is closed to further replies.

# factorial program

This topic is 6113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Here''s my code. How do I make it get the factorial of a? #include int main() /* This is a program which calculates the factorial of a number */ /* >This is what it says: >Write a program which calculates the factorial of a number, it should >1 declare 3 integers: the no we are calculating the factorial of, a >number to hold the answer and a counter for the while loop >2 use a while loop to multiply the answer the correct no of times >3 multiply the answer by the appropriate amount each time round the >while loop >4 print an answer in the format " the factorial of 4 is 24" > > */ { int a,b,c; printf("Input number"); scanf("%d",&a); c = a-1; while (c >= 1) { b = a*c; c--; } printf ("The factoral is %d\n", b ); return 0; } "I envy you, who has seen it all" "And I, young sir, envy you, who have yet to see it for the first time..." - Daniel Glenfield 1st October 2001

##### Share on other sites
phew! got it! thanks to the guys on general programming! I got in just before you, but thanks!!!

#include

int main()

{
int a,b,c;

printf("Input number");

scanf("%d",&a); /* %d is for an int I think in C. &a assigns that value to a */

c = a-1;

b = 1;
while (c >= 1)

{

b = b*a--;
c--;

}
printf ("The factoral is %d\n", b );
return 0;
}

"I envy you, who has seen it all"
"And I, young sir, envy you, who have yet to see it for the first time..."
- Daniel Glenfield
1st October 2001

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5
gaxio
12

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631724
• Total Posts
3001897
×