📄 求最大最小值.cpp
字号:
/*/////////////////////////////////////////////////////////
Func:求数据文件中的最大值与最小值,与它们之间的差
///////////////////////////////// zhao 2002/9/2 /////////*/
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
void main()
{
char fin[50]={'\0'};
char fout[50]={'\0'};
cout<<"Type the file :";
cin>>fin;
strncpy(fout,fin,strlen(fin)-4);
strcat(fout,"_result.dat");
ifstream source(fin);
ofstream result(fout);
if(!source)
{
cout<<"can't open file"<<fin<<endl;
return;
}
if(!result)
{
cout<<"can't create file"<<fout<<endl;
return;
}
float sdata=0;
float max=0;
float min=0;
float range;
source>>sdata;
max=sdata;
min=sdata;
while(!source.eof())
{
source>>sdata;
if(sdata>max)
{
max=sdata;
}
else if(sdata<min)
{
min=sdata;
}
}
range=max-min;
result<<max;
result<<"\n";
result<<min;
result<<"\n";
result<<range;
result<<"\n";
source.close();
result.close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -