1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
sort.cpp : Defines the entry point for the console application.
//
//
#include "stdafx.h"
#include "iostream"
using namespace std;
void main()
{
double int Numbers[26], Primes[]={2, 3, 5, 7, 11, 13, 17, 19, 23};
int i, j, k, l, m, n;
//
cout<<"\n";
cout<<"\t"<<"Hi, Welcome to the random generator number sorter and prime number identifier.....";
cout<<"\n";
cout<<"\n";
cout<<"\n";
//
cout<<"\t";
for (i=1; i<=25; i++)
{
//
Numbers[i]=rand()%25+1;
cout<<Numbers[i]<<" ";
}
//
cout<<"\n";
cout<<"\n";
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"\n";
for (j=1; j<=23; j++)
{
for (i=1; i<=25-j; i++)
{
if (Numbers[i]>Numbers[i+1])
swap(Numbers[i+1],Numbers[i]);
}
}
cout<<"\t";
for (i=1; i<=25; i++)
{
cout<<Numbers[i]<<" ";
}
cout<<"\n";
cout<<"\n";
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"\n";
cout<<"\t";
bool printed;
for (i=1; i<26; i++)
{
printed = false;
for (n=1; n<9; n++)
{
if (Numbers[i]==Primes[n] )
{
printed = true;
cout<<"'"<<Primes[n]<<" ";
}
}
if (!printed)
{
cout<<Numbers[i]<<" ";
}
}
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
}
|