TURN PRIME NUMBERS IN TO DESCENDING ORDER in C++

// ADD A FUNCTION TO TURN PRIME NUMBERS IN TO DESCENDING ORDER

#include<iostream>
using namespace std;
int primes(int * a,int start,int end);
void descending(int arr[],int size);
int main(){
int start,end;
int arr[100]={};
cout<<" enter the starting value "<<endl;
cin>>start;
cout<<endl<<" enter the end point "<<endl;
cin>>end;
int a=primes(arr,start,end);
cout<<" so the prime numbers are "<<endl;
cout<<a<<endl;
for(int x=0;x<a;x++){
cout<<x<<"  =  "<<arr[x]<<" "<<endl;
}
cout<<endl<<" now we are going to sort numbers in descending order "<<endl;
 descending(arr,a);
 for(int x=0;x<a;x++){
cout<<x<<"  =  "<<arr[x]<<" "<<endl;
}
}
int primes(int * a,int start,int end){
int iter=0;
for(int x=start;x<=end;x++){

int count=10;
for(int y=2;y<=(x/2);y++){
if(x%y==0){
count=-5;

}
}
if(count>0){
*a++=x;
iter++;
}
}
return iter;
}
void descending(int arr[],int size){
 for(int x=0;x<size;x++){
 for(int y=0;y<size-x-1;y++){
  if(arr[y+1]>arr[y]){
  int temp=arr[y];
  arr[y]=arr[y+1];
  arr[y+1]=temp;
  }
 }
}


}













Previous
Next Post »

Comments:

Disqus Shortname