Compose a program that will determine all numbers of the form 2abac divisible by n, where n is a given nonzero natural number.Make this program with while and don't use subprograms please. make the program as simple as posibble
2abac means : a number consisting of 5 digits the first digit should be 2 and the second digit equal to the digit 4
My guess is that it means base-10 digits, e.g. 23437 23435 works for n = 109.
So, for a given n, find all (a, b, c) such that 2 * 10^4 + a * 10^3 + b * 10^2 + a * 10^1 + c * 10^0 ≡ 0 (mod n).
But show some effort yourself first.
#include <iostream>
usingnamespace std;
int main()
{
int n;
cout << "Enter n: "; cin >> n;
for ( int a = 0; a < 10000; a += 1010 )
{
for ( int b = 0; b < 1000; b += 100 )
{
for ( int c = 0; c < 10; c++ )
{
int test = 20000 + a + b + c;
if ( !( test % n ) ) cout << test << '\n';
}
}
}
}
@denispopescuo,
You didn't seriously report me for answering the (flawed?) question that you put up the first time, did you?
What are the limits on your numbers a, b, c? That product will overflow pretty fast. Also, if a, b, c are "given" numbers, and so is n, then it's a bit of a non-problem, don't you think?
You could change any of the for loops to a while loop, but it doesn't seem much of an advantage.
You could check all the multiples of n between 20000 and 29999, finding their digits and writing out those whose second digit matched the fourth. Given the amount of operations, that doesn't seem an advantage.