Factorial-c++

Hello, I want to print the factorial of a number slightly different . I am very new to c so I would like to have some help here. Suppose I give the input as 5 it means I will get 120 as my output…when all the logics are right. But what I want as my output is as like this 1 2 6 24 120

like first fi then again fi like that . I am a bit confused with the logic so please someone help me.

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream fact("factorial.txt");
int i,n,f=1;
cin>>n;
for(i=1;i<=n;i++)
{
f=f*i;
fact<<i<<" ";
}
fact<<endl;
fact<<f<<" ";



return 0 ;
}

The printing of the output had a mistake, try this

fact << f << endl;

in the for loop

//