Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int * getEvenNumbers (int * array, int size_array) {
- int count1, *array2, count2, n_even;
- n_even = getSize(array, size_array);
- array2 = (int *) malloc(sizeof(int) * n_even);
- count2 = 0;
- for(count1 = 0; count1 < size_array; count1++) {
- if(array[count1]%2 == 0) {
- array2[count2] = array[count1];
- count2++;
- }
- }
- return array2;
- }
- int getSize (int * array, int size_array) {
- int count1, n_even = 0;
- for(count1 = 0; count1 < size_array; count1++) {
- if(array[count1]%2 == 0) {
- n_even++;
- }
- }
- return n_even;
- }
- int main() {
- int terms, *point, *arr, count1, size_even_array;
- printf("\nHow many random terms would you like? \nPlease enter a positive integer: \n");
- scanf("%d", &terms);
- arr = (int*) malloc (sizeof(int) * terms);
- srand ((unsigned int) time (0));
- printf("\nThe numbers of the set are: \n");
- for(count1 = 0; count1 < terms; count1++) {
- arr[count1] = rand();
- printf("%d \t", arr[count1]);
- }
- printf("\n\nThe even numbers of the set are: \n");
- point = getEvenNumbers(arr, terms);
- size_even_array = getSize(arr, terms);
- for(count1 = 0; count1 < size_even_array; count1++) {
- printf("%d \t", point[count1]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement