>> really need to fin the proper code for factorial using successive addition
I think the factorial code has a combination of logic and syntax errors. Here's my logic:
factorial is successive multiplication:
3! = 3 * 2 * 1
mutiplication can be viewed as serial addition
3 * 2 = 3 + 3
Note that that means 3! is same as 3 * 2! and 4! is
4 * 3 * 2 = 4 * (3 + 3) = 4 * 6 = 4 + 4 + 4 + 4 + 4 + 4
or 4! = 4 * 3!;
So by extension, n! = n * (n - 1)!
This means you should be able to start with the lower factorials and work your way up to the desired factorial. Which is what I think your code is trying to do, but explaining your logic with comments is very important. And here's the piece of the logic that I think you have wrong. Each new factorial on the way up is the current number added to itself by the prior factorial number of times.
And here's my comments on your code using my logic on your code and commenting on the errors I see.
int main()
{
int num, fact = 6, temp =1, i , j; //initialize fact to 1.
cout<<"Enter a factorial ";
cin>>num;
for(i = 2; i <= num; i++)
fact=0; /*don't reset fact to zero every time. fact is ever increasing each time through the inner loop. It should be the same as the current number, not zero each time the inner loop starts. You can figure out what variable represents the current number*/
//here's one of those errors from not indenting properly.
{
for(j = 1; j <= 1; j++)-------said code doesnt have effect---because the { should be right after the first for loop, not where it is.
/*this loop controls how many times the current number is added to itself to get the current factorial. the terminating condition is wrong as written, you need the prior factorial repeats. I'll let you figure out which variable in your code represents the prior factorial.*/
fact=fact+temp; //you're adding the wrong value each time through the loop.
temp=fact; //this should be outside the inner loop
}
}