In: Computer Science
what is the best code to construct a C++ program that finds a five digit number; This number should reverses the order of its digits when multiplied by four. Also, how many five digits numbers are there in which the sum of the digits is even.
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
using namespace std;
bool isOk(int num)
{
string n = to_string(num);
string rev = to_string(num*4);
reverse(rev.begin(), rev.end());
return rev.compare(n)==0;
}
int main() {
// declare variables
int start = 10000;
int end = 99999;
// loop from start to end
int count = 0;
for(int i=start;i<=end;i++)
{
if(isOk(i))
{ cout<<i<<endl;
count++;
}
}
cout<<"There are only "<<count<<"
such numbers.";
return 0;
}
=============================
SCREENSHOT: