计算1-10的阶乘,并保存到文件中去:
#include<iostream>
#include<fstream>
using namespace std;
void main()
{
ofstream outfile;
int i,j;
outfile.open("C:\\Users\\good\\Desktop\\我的旅途\\项目五十四-文件操作\\outfile.txt");
for(i=1;i<=10;i++)
{
int temp=1;
for(j=i;j>0;j--)
{
temp*=j;
}
outfile<<i<<"!:"<<'\t'<<temp<<endl;
}
outfile.close();
}
计算结果: