2-prime
(Time: 1 sec. Memory: 16 MB Difficulty: 28%) A number is called 2-simple if the primes are composed of digits of this number in ascending and descending order.
It is required to write a program that, by a given number, determines its 2-simplicity.
Input data
The input fileINPUT.TXTcontains a positive integerN(10 <N <10 9 ).Output
In the output file OUTPUT.TXT output the message "Yes" if the numberNis 2-simple and "No" - otherwise.
Here is my code:
#include <iostream> #include <string> #include <stdlib.h> using namespace std; int i ,x,k, sum , n, re; int main() { cin >> n; if (n < 10) { re += 1; } for (int i = 2; i < n - 1; i++) { if (n%i == 0) { re += 1; } } string s = to_string(n); reverse(s.begin(), s.end()); sum = atoi(s.c_str()); for (int i = 2; i < sum - 1; i++) { if (sum % i == 0) { re += 1; } } if (re == 0) { cout << "Yes"; } else { cout << "No"; } return 0; } Writes what's wrong. Where is the mistake?
revariable is not initialized before use. - Yaantredeclared at the namespace level, which means that it is implicitly initialized to zero. - AnT 7:05 pm