Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int maxNumber(int n1, int n2){
- if(n1 >= n2)
- return n1;
- else
- return n2;
- }
- int minNumber(int n1, int n2){
- if(n1 >= n2)
- return n2;
- else
- return n1;
- }
- int main()
- {
- cout << "Give me 2 numbers and between them I will find all the perfect squares between them.\n";
- int n1;
- int n2;
- cin >> n1;
- cin >> n2;
- cout << endl;
- int maximum = maxNumber(fabs(n1), fabs(n2));
- int minimum = minNumber(fabs(n1), fabs(n2));
- //cout << maximum << " " << minimum << endl;
- vector <int> squares = vector <int>();
- for(int i=minimum; i<maximum+1; i++){
- if(sqrt(i) == (int)(sqrt(i))){
- squares.push_back(i);
- }
- }
- // Display all elements
- cout << squares.size() << " perfect squares found:\n";
- for(unsigned int i=0; i<squares.size(); i++){
- cout << squares[i] << endl;
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement