Please Help Me Do The Descending Sortation

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();} }
1
2
3
4
get number(number should be >= 2)
for all x from number to 2
    if x is prime
       print x
reverse the algorithm
@anup30 reverse???
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
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.
reverse the algorithm


i meant the OPs two for loops.
i meant the OPs two for loops.
OP??
Original Poster == odi1496
ok
Topic archived. No new replies allowed.