I have a data file in which first column varies from -180 to +180 with a width of 5, while the second column is some corresponding value. i need to find minima from second column for one corresponding value of first say -180,print that,then subsequently find minima for -175 from second column print that and so...I have code for finding minima when i have only one column. How do I include this loop
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream myfile("ma3.txt");
if(myfile.is_open())
{
int arrSize=0.0;
double arr[2000];
double min=0;
while(true)
{
double x,y;
myfile>>x;
if(myfile.eof()) break;
arr[arrSize++]=x;
}
//for(int i=0; i<arrSize; ++i)
// cout<<arr[i]<<"";
//cout<<endl;
min=arr[0];
for(int i=0;i<arrSize;i++)
{
{
if(arr[i]<min)
{
min=arr[i];
}
}
}
cout<<"Smallest element:";
cout<<min;
cout<<endl;
}
else
{
cout<<"Unable to open file";
}
return 0;
}
The input data:
-180 431.845
-180 434.337
-180 436.819
-180 439.289
-180 469.936
-180 472.152
-180 474.343
-180 476.509
-180 478.649
-180 480.761
-180 482.846
-180 484.902
-180 486.929
-180 488.926
-175 387.566
-175 384.891
-175 382.216
-175 379.541
-175 376.868
-175 374.197
-175 371.53
-175 368.867
-175 366.209
-175 363.557
-175 360.912
-175 358.275
-175 355.648
-175 353.03
-175 350.422
-175 347.826
-175 345.243
-175 342.673
-175 340.117
-175 337.576
-175 335.05
-175 332.541
-175 330.05
-175 327.576