Hi there,
I am currently lost on how to fix my code for this assignment. Any help will greatly be appreciated!
Write a function called fillArray that will fill an array of any size with random numbers in the range of 1 - 100.
Write a separte function called printArray that will print an array of any size.
Write a third function called countEvens which will count and return the number of even numbers in the array.
In main create an array that holds 25 ints. Use your functions to fill, print, and count the number of even numbers. You should
Fill the array
Print the array
Print the number of even numbers in the array
What not to do
Using any of the following will drop your grade for this assignment by 70%
global variables
cin in any funciton other than main
cout in any funciton other than main and printArray
goto statements
It looks like this:
16
90
90
48
80
45
63
28
32
12
77
80
75
83
90
62
56
4
12
76
52
5
There are 18 even numbers in the array
Press any key to continue . . .
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
|
#include <iostream>
#include <stdio.h>
#include <time.h>
using namespace std;
void fillArray(int num[], int size);
void printArray(int num[], int size);
int countEvens(int num[], int size);
int main()
{
int num[25], count;
fillArray(num, 25);
printArray(num, 25);
count = countEvens(num, 25);
printf("There are %d even integers in the array.", count);
return 0;
}
void fillArray(int num[], int size)
{
int i;
for (i = 0; i < size; i++)
{
int c = rand() % 100 + 1;
if (c>0 && c<101)
num[i] = c;
}
}
void printArray(int num[], int size)
{
int i;
for (i = 0; i < size; i++)
printf("%d\n", num[i]);
}
int countEvens(int num[], int size)
{
int count = 0, i;
for (i = 0; i < size; i++)
{
if (num[i] % 2 == 0)
count++;
}
return count;
}
| |