Please Help Me Do The Descending Sortation

Oct 16, 2014 at 11:19am
could you Help me.. how to Add reverse the Answer (Add The Descending Sortation)?

if i Put 10 on "n" The Answer Is : 2,3,5,7
But I Want The Answer To Be : 7,5,3,2
And i dont know how.. please help :(
Idont Understand Even I read The Instruction... Please

My Current Program :

#include<iostream.h>
#include<conio.h>
void main() {
int n,c,x,y;

cout<<"Put a Number (we will Find The Prime Number) : ";
cin>>n;

for(x = 1; x < n; x++)
{c=0;
for( y = 1; y <= x; y++)
{ if(x % y == 0)
c++; }
if(c==2)
{ cout<<x<<" "; }


getch();} }
Oct 16, 2014 at 11:26am
1
2
3
4
get number(number should be >= 2)
for all x from number to 2
    if x is prime
       print x
Oct 16, 2014 at 11:28am
reverse the algorithm
Oct 16, 2014 at 11:32am
@anup30 reverse???
Oct 16, 2014 at 11:57am
for(x = n; x >=2; x--)
{c=0;
for( y = x-1; y >=2; y--)
{
if(x % y == 0)
c++;
}
if(c==0)
cout<< x<< " ";
}
Last edited on Oct 16, 2014 at 11:58am
Oct 16, 2014 at 12:10pm
1. Please use the code tags, everyone. Referring to line number makes commenting easier.

2. What is the point of reversing the
if x is prime

That condition resolves to a boolean no matter which way you look at it (but some ways may be faster).


All the necessary magic is in the line 2 of shadowCODE's post.
Oct 16, 2014 at 12:22pm
reverse the algorithm


i meant the OPs two for loops.
Oct 16, 2014 at 12:27pm
i meant the OPs two for loops.
OP??
Oct 16, 2014 at 12:32pm
Original Poster == odi1496
Oct 16, 2014 at 12:33pm
ok
Topic archived. No new replies allowed.