64,639
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
void main()
{
int next[100],count=0,t;
ifstream fin;
ofstream fout;
fin.open("1.txt");
if(fin.fail())
{
cout <<"input the file is fail(1)." <<endl;
fin.close();
return;
}
while(fin>>next[count])
{
count++;
}
fin.close();
fin.clear();
fout.open("2.txt");
if(fout.fail())
{
cout <<"output the file is fail(3)";
fout.close();
return;
}
if (count%2)//奇数
{
t=next[count/2];
}
else
{
t=next[(count-1)/2]+next[(count+1)/2];
t/=2;
}
cout << "the median is :" <<t;
fout << "the median is :" <<t;
fount.close();
return;
}