Listing
Hi, how do i output a list,1-5 of the following factorial?
#include <stdio.h>
#include <stdlib.h>
#define fact 5
int main(void)
{
int i,result=1;
for (i=fact;i>=1;i--)
result*=i;
printf("factorial of (%d) = %d\n", fact, result);
return(EXIT_SUCCESS);
}
Related Article: Combine 2 programs (curl and popen)
is a C discussion thread by red711 that has 1 reply, was last updated 1 year ago and has been tagged with the keywords: combine, curl, files, popen.
Valiantangel
Junior Poster in Training
89 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
yes your send ans is good.But do u need to use the two loops?Can it be achieved using 1?
for (j = 0; j < fact; j++, _fact--)
for (i = _fact ; i >= 1; i--)
Also i cant seem understand what does j do?
Valiantangel
Junior Poster in Training
89 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Never mind i got the ans.
Valiantangel
Junior Poster in Training
89 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by
nullptr For me this is better and simpler:
#include <stdio.h>
#include <stdlib.h>
#define fact 5
int main(void)
{
int i,result=1;
for (i=1;i<=fact;i++) {
result*=i;
printf("factorial of (%d) = %d\n", i, result);
}
return(EXIT_SUCCESS);
}
pyTony
pyMod
6,330 posts since Apr 2010
Reputation Points: 879
Solved Threads: 989
Skill Endorsements: 27