#include <bits/stdc++.h>
using namespace std;
int scaleBetween(int unscaledNum, int minAllowed, int maxAllowed, int min, int max)
{
int ans;
ans=(maxAllowed - minAllowed) * (unscaledNum - min) / (max - min) + minAllowed;
return ans;
}
int main()
{
int scaleMin, scaleMax,i,n,m;
vector<int>data;
cout<<"Enter Number of data"<<endl;
cin>>n;
cout<<"Enter data"<<endl;
for(i=0;i<n;i++)
{
cin>>m;
data.push_back(m);
}
cout<<"Enter your desired min and max Range"<<endl;
cin>>scaleMin>>scaleMax;
int minRange=*min_element(data.begin(), data.end());
int maxRange=*max_element(data.begin(), data.end());
for (i = 0; i < data.size(); i++)
{
int unscaled = data[i];
int scaled = scaleBetween(unscaled, scaleMin, scaleMax, minRange, maxRange);
cout<<scaled<<endl;
}
return 0;
}
0 comments:
Post a Comment