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 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <cmath>
using namespace std;
bool prime(int);
void find_largest(int[], const int &s, int &);
void count_odds_evens(int[], const int&, int&, int&);
void randomize_array(int[], const int &);
void print_array(int[], const int &);
void find_largest(int n[], const int &s, int &largest)
{
int x = 0;
int y = 0;
for (int i = 0; i < 100; i++)
{
cin >> x;
if (x > y)
y = x;
}
cout << "The biggest number is:" << y << endl;
}
bool prime(int n)
{
if (1 == n)
return false;
for (int i = 2; i <= sqrt(double(n)); i++)
if (n%i == 0)
return false;
return true;
}
void count_odds_evens(int n[], const int &s, int &num_even, int &num_odds)
{
int even_count = 0;
int odd_count = 0;
int integer;
while (true) {
cout << "Please enter an integer\n";
cin >> integer;
if (integer == 0) break; // break outa here
// determine if integer is even or odd
if (integer % 2 == 0)
even_count++;
else
odd_count++;
} // end of while loop
cout << "Number of even elements = " << even_count;
cout << "Number of odd elements = " << odd_count << endl;
}
void randomize_array(int n[], const int &s)
{
srand(unsigned(time(0))); // seed the random number generator
for (int i = 0; i<s; i++)
n[i] = rand() % 100 + 1;
}
void print_array(int n[], const int &s)
{
int spaces = 0, i = 0;
while (i < s)
{
cout << setw(4) << n[i] << " ";
spaces += 6;
if (spaces % 66 == 0)
cout << endl;
i++;
} // while
cout << endl;
}
|