-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFourth_Problem.cpp
More file actions
35 lines (33 loc) · 863 Bytes
/
Fourth_Problem.cpp
File metadata and controls
35 lines (33 loc) · 863 Bytes
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
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int last = 999;
int first_product;
int second_product;
int main(){
int max = 0;
for(int i=last;i>=100;i--){
for(int s=last;s>=100;s--){
int product = i*s;
int reverse = 0;
int divided = product;
while(divided>=1){
int remainder = divided%10;
int length = 1;
int x = divided;
while ( x /= 10 )
length++;
reverse+=remainder*(pow(10,length-1));
divided = (divided-remainder)/10;
}
if(reverse==product && reverse>max){
first_product = i;
second_product = s;
max = reverse;
}
}
}
cout << "MAX IS " <<max << " AND THE PRODUCTS ARE : "<< first_product << "," << second_product<<endl;
return 0;
}