#include <iostream> using namespace std; int main() { int number, n; int divisor, d; int remainder, r; int divisors_count, c = 0; int nd = 0; int cd = 0; int N; int M; cout<<"Enter N, "<<endl; cin>>N; cout<<"Enter M, "<<endl; cin>>M; cout << "This program finds the integer R from N to M (2<=N<M<=1000)\n"; cout << "and the integer R has the maximum number of divisors.\n"; try { if(N<2||N>1000) throw(M); else if(M>1000||M<2) throw(0.1); else { for(n = N; n <= M; n++) { for(d = 2; d < n ; d++) { r = n % d; if (r == 0) { c++; } } if (cd < c) { cd = c; nd = n; } c = 0; } cout << "The integer R is " << nd << "." << '\n'; cout << "It has " << cd << " divisors." << '\n'; } } catch(int) { cout<<"N must be more than 1, equal or more than 2 but less than 1000, "<<endl; } catch(double) { cout<<"M must be less than or equal to 1000 and more than 2, "<<endl; } return 0; }

This post has been edited by **modi123_1**: 14 December 2016 - 12:25 PM

Reason for edit:: In the future, please use the [code] tag button.