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

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

No. You will have to write that yourself.

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

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

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}

commented: pure crap -1

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.

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

commented: Bad solution and 1.5 years do late, too. -4

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."

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.

#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..:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.