Originally Posted by
jjzarabi
There is no output
Oh ok, too bad you didn't mention that minor detail from the start. Sometimes we ask
people, if they want help that it would be much easier for us to read your code if you
could use indentation. Just in case you don't know what that means, I made your code
(with 2 corrections) more readable by indenting your code.
What was my reward? Well, I got output alright, but I don't think it is your desired
result.
The two corrections: (In Green) you declared an int i inside a for loop so I moved it with the
other int declarations. Second, I took msh's suggestion, and used " i <= end " because
that makes sense without additional detail.
Code:
#include <stdio.h>
int main ()
{
int i, start, end, fact=0;
printf("Please enter a starting and larger ending integer so \n "
"I can find the factorial of each of those integer numbers between and including \n"
"the starting and ending integer numbers which are divisible by 2 as well as by 3\n\n");
scanf("%d%d",&start, &end);
printf("\n\n");
for (i=start; i <= end; i++)
{
if(i%2 && i%3 == 0)
{
fact*=fact;
fact=fact-1;
printf("%d",fact);
}
}
printf("\n\n");
return 0;
}
Code:
Here was my input: 1 100
Here was my output: -10-10-10-10-10-10-10-10-1
You wanted output? Well, there ya go!