// Program to find range of set of numbers
#include<iostream>
#include<windows.h>
using namespace std;
int main(void)
{
int l,n,i=0,max=0,min=0,range;
char c;
cout<<"Define length of number set: ";
if(cin>>l)
{}
else
{
cout<<"Error: Only numeric values are allowed, TRY AGIAN...\n\n";
cin.clear();
cin.ignore();
main();
}
if(l<=0)
{
cout<<"Error: Invalid set lenght\n Try again...\n\n";
main();
}
cout<<endl;
cout<<"Enter numbers into the set:\n";
for(i=0;i<l;i++)
{
cin>>n;
if(n>max)
max=n;
if(i==0)
min=n;
if(n<min)
min=n;
}
cout<<"Range of the set is MAX - MIN: "<<max<<" - "<<min<<" = "<<max-min;
}
No comments:
Post a Comment
Comments please: