C++ program code help

HOW DO I STORE AND SORT THE NUMBERS INTO DESCENDING ORDER USING MY CODE?
I have them printing out in ascending order, now I do not know how to print them into descending order.


1) Prompts the user to enter two integer numbers Lower and Upper
2) Prompts the user to enter two more integers, p and q
3) Using a WHILE loop, display all numbers between Lower and Upper that are divisible by either p
4)Modify the program so that it also prints that same series out in descending order as well
5)There should be no repetitions. Numbers that are divisible by both p and q should only be
printed out once.

How do I store the numbers into and array and print them out in descending order?

int main() {
int lower, upper, lower2, lower3, p, q;

cout<< "Enter two numbers to be a Lower and Upper bounds: \n";
cin>> lower >> upper;

cout<< "Enter two numbers to be the p and q values: \n";
cin>> p >> q;
cout<< "Ascending order: \n";

while(lower<=upper){
lower++;
lower2 = lower;


if(lower2%p==0 || lower2%q==0){

cout<< lower2<< ", " ;
}

}
how to store numbers into int array?

just a simple example:

1
2
3
4
5
6
int Iarray[10]={0};

for(int i = 0; i<= 9; ++ i)
{
Iarray[i] = i;
}
Last edited on
and about Descending order?

a simple way!

#include <iostream>

using namespace std;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
	int att[10] = {1,6,4,5,9,6,4,8,3};

	for(int i = 0; i <= 9; ++i)
	{
		for(int b = 0; b <= 9; ++b)
		{
			if(att[i]>att[b])
			{
				swap(att[i], att[b]);
			}
		}
	}
}
Last edited on
Topic archived. No new replies allowed.