标签:max-min-搜索int类型数字文件中的最大数和最小数写到屏幕
Max-Min-搜索int类型数字文件中的最大数和最小数写到屏幕:
//Max-Min-搜索int类型数字文件中的最大数和最小数写到屏幕
#include<iostream>
#include<fstream>
#include<cstdlib>
int main()
{
using namespace std;
ifstream fin;
ofstream fout;
int max,min,tem;
fin.open("numbers.dat");
if(fin.fail())
{
cout<<"Input file opening failed.\n";
exit(1);
}
fin>>max;
min = max;
while(! fin.eof())
{
fin>>tem;
max = max>tem?max:tem;
min = min<tem?min:tem;
}
cout<<"The max number is "<<max<<endl;
cout<<"The min number is "<<min<<endl;
fin.close();
return 0;
}文件内容:
11 22 33 44 55 66 77 88 99
结果:
The max number is 99 The min number is 11
Max-Min-搜索int类型数字文件中的最大数和最小数写到屏幕
标签:max-min-搜索int类型数字文件中的最大数和最小数写到屏幕
原文地址:http://9320314.blog.51cto.com/9310314/1547690