forked from arianamestel/CSCI211
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMestelAriana_Assignment_001.cpp
34 lines (31 loc) · 1.1 KB
/
MestelAriana_Assignment_001.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// MestelAriana_Assignment_001.cpp
/******
Assignment 1: Perfect Square Problem
Find the Value
Write a program to find and print the first perfect square (i*i) whose last two digits are both odd.
There is no such thing as a perfect square whose last two digits are both odd. To prove this, the
program will keep adding to the value of n to see when the last two digits of its square are both odd.
The program will keep looping anf never find an answer because it is not possible.
To make this program work, n cannot be an int because it isnt large enough and will stop at 65537.
To fix this i stores the variable n as long.
*******/
#include <iostream>
using namespace std;
int main () {
long n = 1;
while (true) {
long square = n * n;
if ((square > 9) && (square % 2 == 1) && ((square / 10) % 2 == 1)) {
cout << n * n << " is a perfect square whose last two digits are odd." << endl;
break;
}
else {
n++;
}
if (n > 100000) {
cout << "There is no such thing as a perfect square whose last two digits are odd." << endl;
break;
}
}
return 0;
}