asking clearly big question in numbers are prime together

hi gentles, i tested a code that
doesn't work. and i want you
helping for the shortest code
quickly. It's maddening me. The
code's duty is showing numbers
( less than 20 ) are prime
together (two numbers have no
parallel multiples ) . And i want
you helping for a right code. The
output should be like this:
2 and 3
2 and 5
2 and 7
...
18 and 19
thanks much ,if you can help to
end it before tommorrow... Can
anybody write it??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  
#include <iostream>
using namespace std ;
int main()
{
int i,j;
for ( i = 1 ; i <= 19 ; i++ )
{
for ( j = i ; j <= 19 ; j++ )
{
if ( i % j != 0 && j % i != 0 )
cout << i << " and " << j << endl;
}
}
return 0;
}
Last edited on
You don't need to make new topic about same thing. This is your 3rd topic of this same question.

http://www.cplusplus.com/forum/beginner/148278/
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

int main()
{
    // for each pair of numbers i and j in [2,20), i<j
    // think: why should i be less than j? (or equivalently, j be less than i)?
    for( int i = 2 ; i < 20 ; ++i )
        for( int j = i+1 ; j < 20 ; ++j )
        {
            // http://en.cppreference.com/w/cpp/language/continue

            if( i%2 == 0 && j%2 == 0 ) continue ; // both even // think: what does continue do?
            if( i%3 == 0 && j%3 == 0 ) continue ; // both multiples of three
            if( i%5 == 0 && j%5 == 0 ) continue ; // both multiples of five
            if( i%7 == 0 && j%7 == 0 ) continue ; // both multiples of seven
            std::cout << i << ' ' << j << '\n' ; // do not have a common multiple in [2,3,5,7]

            // think: why aren't we testing for divisibility by 6?
            // think: why aren't we testing for divisibility by 11?
            // do not, repeat *do not*, proceed before you have answers to these questions
        }
}
Topic archived. No new replies allowed.