1,105,447 Community Members

Find the factorial of a number using do while loop

Member Avatar
sayoojya
Newbie Poster
1 post since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-8
 

Write a C program to find the factorial of a number using do while loop?

Member Avatar
Ancient Dragon
Achieved Level 70
27,632 posts since Aug 2005
Reputation Points: 5,232 [?]
Q&As Helped to Solve: 3,037 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

Write a C program to find the factorial of a number using do while loop?

No. You will have to write that yourself.

Member Avatar
jephthah
Posting Maven
2,572 posts since Feb 2008
Reputation Points: 1,888 [?]
Q&As Helped to Solve: 196 [?]
Skill Endorsements: 5 [?]
 
0
 

Write a C program to find the factorial of a number using do while loop?

well, yes. yes, i can. thank you! :)

Member Avatar
daisy192
Newbie Poster
13 posts since Feb 2010
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I am give you algorithm to find the factorial of given no. Try your self.
1. Intialize variable no,fact=1,ans
2. Get value of no from user.
3. Do while(no>=fact)
4. Take answer in ans variable
5. Display ans


{snip}

Member Avatar
jephthah
Posting Maven
2,572 posts since Feb 2008
Reputation Points: 1,888 [?]
Q&As Helped to Solve: 196 [?]
Skill Endorsements: 5 [?]
 
0
 

I am give you algorithm to find the factorial of given no. Try your self.
1. Intialize variable no,fact=1,ans
2. Get value of no from user.
3. Do while(no>=fact)
4. Take answer in ans variable
5. Display ans

huh?? what does this most incoherent mess of pseudo-code mean? this is garbage.

Member Avatar
soundu
Newbie Poster
1 post since Aug 2011
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-2
 

start
set the number be i
initialize fact=1
fact=fact*i
display the value
stop

Member Avatar
Jamblaster
Junior Poster in Training
55 posts since Aug 2011
Reputation Points: 15 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

Ok I can't give you the answer, but here is what a programming instructor once told me:

"Inside the loop, you multiply the counter times the accumulated number up to that point (the accumulator has to be initialized to 1 before the loop). So if the user enters a 3--The first time through the loop, the counter is 1, so 1 * the accumulator 1 is 1. Second time through the loop, the counter is 2, so 2 * the accumulator 1 is 2. Third time through the loop, the counter is 3, so 3 * the accumulator 2 is 6. This is where the loop ends, and after the loop, 6 would be displayed as the answer."

Member Avatar
YAMNA MIDHAT
Junior Poster in Training
57 posts since Aug 2011
Reputation Points: -5 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 1 [?]
 
0
 

huh?? what does this most incoherent mess of pseudo-code mean? this is garbage.

in easy words we can simply write the algorithm as:
1.set a variable to be 1
2.scan the no from user for which he needs the factorial.
3.inside the loop
a. set the loop to run n-1 times where n is the no inputted by user
b.then start multiplying the variable which was declared as 1 with the one used in loop.
4.show the result.

its so simple try it .i can understand your problem as i was also stuck in a problem like this few weeks ago. hope you understand all this written above.

Member Avatar
dharini6030
Newbie Poster
1 post since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
#include<stdio.h>
void main()
{
int fact=1,no,i=1;
printf("Enter no whose factorial is to be found/n");
scanf("%d",&no);
do
{
fact*=i;
i++;
}while(i<=no);
printf("Factorial of %d=%d\n",no,fact;
}

try this code... hope so it will work..:)

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article