Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- c_arrays_with_pointers_with_dynamic_memory_allocation.c
- Updated: 2021.05.04 , by Dragan Milicev, https://www.facebook.com/dmilicev
- In C language string is actually a one-dimensional array of characters
- which is terminated by a null character '\0'.
- // Function to print array, n is number of elements in array arr[]
- // text[] describes the shown array arr[]
- void printArray( char *text, int *arr, int n )
- // Fills array arr with n integers starting from first
- // and update pointer to number of elements pn with n.
- void fill_array_with_integers( int *arr, int *pn, int n, int first )
- // Refills (reset) two arrays.
- // Fills array arr1 with n1 integers starting from first1 and update pn1,
- // Fills array arr2 with n2 integers starting from first2 and update pn2.
- void fill_two_arrays_with_integers( int *arr1, int *pn1, int n1, int first1,
- int *arr2, int *pn2, int n2, int first2 )
- // Refills (reset) array and print it.
- // Fills array arr1 with n1 integers starting from first1 and update pn1.
- void fill_and_print_array_with_integers( int *arr1, int *pn1, int n1, int first1 )
- // Refills (reset) two arrays and print them.
- // Fills array arr1 with n1 integers starting from first1 and update pn1,
- // Fills array arr2 with n2 integers starting from first2 and update pn2.
- void fill_and_print_two_arrays_with_integers( int *arr1, int *pn1, int n1, int first1,
- int *arr2, int *pn2, int n2, int first2 )
- // Copies the array arr2 to the array arr1 and updates pointer n1.
- // Function itself extends arr1 array to have enough space for arr2 array.
- // Returns the copied array arr1.
- int *arrcpy( int *arr1, int *n1, int *arr2, int n2 )
- // Concatenates array arr2 to array arr1 and updates pointer n1.
- // Function itself extends array arr1 to have enough space for array arr2.
- // Returns the concatenated array arr1.
- int *arrcat( int *arr1, int *n1, int *arr2, int n2 )
- // Inserts a new element num into the array of n elements,
- // in place of the index pos_index. Returns array arr.
- int *insert_num_into_array(int *arr, int *n, int num, int pos_index)
- // Inserts array arr2 with n2 elements into array arr1 with n1 elements,
- // in place of the index pos_index. Returns array arr.
- int *insert_arr2_into_arr1(int *arr1, int *n1, int *arr2, int n2, int pos_index)
- // If num exists in array arr of n integers,
- // returns index of num in array arr,
- // otherwise returns -1.
- int arr_find_num(int *arr, int n, int num)
- // If subarray arr2 with n2 integers exists in array array arr1 with n1 integers,
- // returns the index of the beginning of the subarray arr2 in array arr1,
- // otherwise returns -1.
- int arr_find_subarr(int *arr1, int n1, int *arr2, int n2)
- // In array arr with n elements deletes one element at position pos_index
- int *del_array_element_at_pos_index(int *arr, int *n, int pos_index)
- // In array arr1 with n1 elements deletes a subarray arr2 that has n2 elements
- int *del_subarray_into_array(int *arr1, int *n1, int *arr2, int n2)
- // Deletes odd elements in array arr with n elements
- int *del_odd_array_elements(int *arr, int *n)
- // Deletes even elements in array arr with n elements
- int *del_even_array_elements(int *arr, int *n)
- // Deletes all elements in array arr with n elements
- int *del_all_array_elements(int *arr, int *n)
- // The auxiliary sort function replaces xp and yp with each other
- void swap(int *xp, int *yp)
- // Bubble sort sorts array arr of n elements in ascending order
- void sort_array_ascending(int *arr, int n)
- // Bubble sort sorts array arr of n elements in descending order
- void sort_array_descending(int *arr, int n)
- // Sums the n elements of the array and returns that sum
- float get_array_sum(int *arr, int n)
- // Returns mean value of array arr with n elements.
- // Mean and average are the same.
- // Mean of an array = (sum of all elements) / (number of elements)
- float get_array_mean(int *arr, int n)
- // Returns median of n array arr elements.
- // Median of a sorted array of size n is defined as
- // the middle element when n is odd and
- // average of middle two elements when n is even.
- // Since the array is not sorted here, we sort the array first, then apply above formula.
- float get_array_median(int *arr, int n)
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- #include <stdlib.h> // for malloc() and realloc()
- #include <string.h>
- // Function to print array, n is number of elements in array arr[]
- // text[] describes the shown array arr[]
- void printArray( char *text, int *arr, int n ){
- int i;
- printf("%s", text );
- for(i=0; i<n; i++)
- printf("%3d", *(arr+i) );
- printf("\n");
- }
- // Fills array arr with n integers starting from first
- // and update pointer to number of elements pn with n.
- void fill_array_with_integers( int *arr, int *pn, int n, int first ){
- int i;
- // reallocate sufficient space
- arr = (int *)realloc( arr, (size_t)n * sizeof(int) );
- if( arr == NULL ) {
- fprintf(stderr, "\n\n arr realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- *pn = n;
- for(i=0; i<*pn; i++) // fill array arr with n integers from first
- *(arr+i) = first+i;
- } // fill_array_with_integers()
- // Refills (reset) two arrays.
- // Fills array arr1 with n1 integers starting from first1 and update pn1,
- // Fills array arr2 with n2 integers starting from first2 and update pn2.
- void fill_two_arrays_with_integers( int *arr1, int *pn1, int n1, int first1,
- int *arr2, int *pn2, int n2, int first2 ) {
- fill_array_with_integers(arr1,pn1,n1,first1);
- fill_array_with_integers(arr2,pn2,n2,first2);
- } // fill_array_with_integers()
- // Refills (reset) array and print it.
- // Fills array arr1 with n1 integers starting from first1 and update pn1.
- void fill_and_print_array_with_integers( int *arr1, int *pn1, int n1, int first1 ) {
- fill_array_with_integers(arr1,pn1,n1,first1);
- printArray("\n Before, arr1 = ", arr1, *pn1);
- } // fill_array_with_integers()
- // Refills (reset) two arrays and print them.
- // Fills array arr1 with n1 integers starting from first1 and update pn1,
- // Fills array arr2 with n2 integers starting from first2 and update pn2.
- void fill_and_print_two_arrays_with_integers( int *arr1, int *pn1, int n1, int first1,
- int *arr2, int *pn2, int n2, int first2 ) {
- fill_array_with_integers(arr1,pn1,n1,first1);
- fill_array_with_integers(arr2,pn2,n2,first2);
- printArray("\n Before, arr1 = ", arr1, *pn1);
- printArray("\n Before, arr2 = ", arr2, *pn2);
- } // fill_array_with_integers()
- // Copies the array arr2 to the array arr1 and updates pointer n1.
- // Function itself extends arr1 array to have enough space for arr2 array.
- // Returns the copied array arr1.
- int *arrcpy( int *arr1, int *n1, int *arr2, int n2 ){
- int i;
- // allocate sufficient space, reallocating memory size of arr1 for arr2
- arr1 = (int *)realloc( arr1, (size_t)n2*sizeof(int) );
- if( arr1 == NULL ) {
- fprintf(stderr, "\n\n arr1 realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- for(i=0; i<n2; i++) // copying...
- *(arr1+i) = *(arr2+i);
- *n1 = n2; // update number of elements
- return arr1;
- } // arrcpy()
- // Concatenates array arr2 to array arr1 and updates pointer n1.
- // Function itself extends array arr1 to have enough space for array arr2.
- // Returns the concatenated array arr1.
- int *arrcat( int *arr1, int *n1, int *arr2, int n2 ){
- int i,j;
- // allocate sufficient space, reallocating memory size of arr1 for arr2
- arr1 = (int *)realloc( arr1, (size_t)(*n1+n2)*sizeof(int) );
- if( arr1 == NULL ) {
- fprintf(stderr, "\n\n arr1 realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- for(i=(*n1),j=0; i<(*n1+n2); i++,j++) // adding arr2 to the end of arr1
- *(arr1+i) = *(arr2+j);
- *n1 += n2; // update number of elements
- return arr1;
- } // arrcat()
- // Inserts a new element num into the array of n elements,
- // in place of the index pos_index. Returns array arr.
- int *insert_num_into_array(int *arr, int *n, int num, int pos_index){
- int i;
- // check that pos_index is valid
- if( pos_index < 0 || pos_index > ( (*n)+1 ) ) {
- fprintf(stderr, "\n\n Function insert_num_into_array(), pos_index = %d not valid ! \n\n", pos_index);
- return arr;
- }
- // allocate sufficient space, reallocating memory size of array arr for one new element
- arr = (int *)realloc( arr, (size_t)( (*n)+1) * sizeof(int) );
- if( arr == NULL ) {
- fprintf(stderr, "\n\n arr realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- // we increase the number of array elements by one because we insert one new element
- (*n)++;
- i = (*n) - 1; // i is the index at the end of the extended array
- while( i > pos_index ) { // from the end of the arr to the pos_index
- *(arr+i) = *(arr+i-1); // we move the elements of the array one place to the right
- i--; // the next left element
- }
- *(arr+i) = num; // now i = pos_index and here we insert a new element num
- return arr;
- } // insert_num_into_array()
- // Inserts array arr2 with n2 elements into array arr1 with n1 elements,
- // in place of the index pos_index. Returns array arr.
- int *insert_arr2_into_arr1(int *arr1, int *n1, int *arr2, int n2, int pos_index) {
- int i, j;
- // check that pos_index is valid
- if( pos_index < 0 || pos_index > ( (*n1)+1 ) ) {
- fprintf(stderr, "\n\n Function insert_arr2_into_arr1(), pos_index = %d not valid ! \n\n", pos_index);
- return arr1;
- }
- // allocate sufficient space, reallocating memory size of array arr1 for new array arr2
- arr1 = (int *)realloc( arr1, (size_t)( (*n1) + n2 ) * sizeof(int) );
- if( arr1 == NULL ) {
- fprintf(stderr, "\n\n arr1 realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- // we increase the number of arr1 elements by n2 because we insert new array arr2
- (*n1) += n2;
- i = (*n1) - 1; // i is the index at the end of the extended array arr1
- while( i > pos_index+n2-1 ) { // from the end of the arr1 to the pos_index+n2
- *(arr1+i) = *(arr1+i-n2); // we move the elements of the array n2 places to the right
- i--; // the next left element
- }
- j = n2 - 1; // j is index at the end of the arr2 with n2 elements
- while( j >= 0 ) { // from the end of the arr2 to the left
- *(arr1+i) = *(arr2+j); // we copy the elements of the arr2 to arr1
- i--; // the next left element
- j--; // the next left element
- }
- return arr1;
- } // insert_arr2_into_arr1()
- // If num exists in array arr of n integers,
- // returns index of num in array arr,
- // otherwise returns -1.
- int arr_find_num(int *arr, int n, int num){
- int i;
- for(i=0; i<n; i++) // for all n elements in array arr
- if( *(arr+i) == num )
- return i; // returns index of num in array arr
- return (-1); // num not found in array arr
- } // arr_find_num()
- // If subarray arr2 with n2 integers exists in array array arr1 with n1 integers,
- // returns the index of the beginning of the subarray arr2 in array arr1,
- // otherwise returns -1.
- int arr_find_subarr(int *arr1, int n1, int *arr2, int n2){
- int i=0, j=0;
- // for all elements of arr1
- while( i < n1 ){ // if first element of subarray arr2 match, check the whole arr1
- while( i<n1 && j<n2 && *(arr1+i) == *(arr2+j) ){
- i++; // next element of array arr1
- j++; // next element of subarray arr2
- }
- if( j == n2 ) // if complete subarray arr2 match, return starting index
- return ( i - j ); // returns the index of the beginning of the subarray arr2 in array arr1
- i++; // next element of array arr1
- }
- return (-1); // subarray arr2 not found in array arr1
- } // arr_find_subarr()
- // In array arr with n elements deletes one element at position pos_index
- int *del_array_element_at_pos_index(int *arr, int *n, int pos_index) {
- int i=0; // index of the array arr
- // check that pos_index is valid
- if( pos_index < 0 || pos_index > ( (*n)-1 ) ) {
- fprintf(stderr, "\n\n Function del_array_element_at_pos_index(), pos_index = %d not valid ! \n\n", pos_index);
- return arr;
- }
- while( i < pos_index ) // from the begin of the arr to the pos_index
- i++; // the next element
- while( i < *n ) { // from the pos_index to the end of the arr
- *(arr+i) = *(arr+i+1); // we move the elements of the array one place to the left
- i++; // the next element
- }
- // we decrease the number of array elements by one because we deleted one element on pos_index
- (*n)--;
- // reallocate sufficient space, reallocating memory size of array arr for one element less
- arr = (int *)realloc( arr, (size_t)( *n ) * sizeof(int) );
- if( arr == NULL ) {
- fprintf(stderr, "\n\n arr realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- return arr;
- } // del_array_element_at_pos_index
- // In array arr1 with n1 elements deletes a subarray arr2 that has n2 elements
- int *del_subarray_into_array(int *arr1, int *n1, int *arr2, int n2){
- int i=0, pos_index;
- // check if subarray arr2 exists in array arr1
- if( pos_index = arr_find_subarr(arr1, *n1, arr2, n2) == -1 )
- return arr1; // in array arr1 there is no subarray arr2
- while( i <= pos_index ) // from the begin of the arr to the pos_index
- i++; // the next element
- i += n2; // we skip the n2 elements of the array arr1
- while( i < *n1 ) { // from the pos_index to the end of the arr1
- *(arr1+i) = *(arr1+n2+i); // we move the elements of the array arr1 n2 places to the left
- i++; // the next element
- }
- // we decrease the number of array elements by n2 because we deleted n2 elements on pos_index
- (*n1) -= n2;
- // reallocate sufficient space, reallocating memory size of array arr1 for n2 elements less
- arr1 = (int *)realloc( arr1, (size_t)( *n1 ) * sizeof(int) );
- if( arr1 == NULL ) {
- fprintf(stderr, "\n\n arr1 realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- return arr1;
- } // del_subarray_into_array()
- // Deletes odd elements in array arr with n elements
- int *del_odd_array_elements(int *arr, int *n){
- int i=0, j=0, n_odd=0;
- while( i < (*n) ) { // for all n elements of array arr
- if( *(arr+i)%2 != 0 ) // if that element is odd,
- n_odd++; // count odd elements
- else{
- *(arr+j) = *(arr+i); // put it in the array
- j++; // prepare index for the next array element
- }
- i++; // the next element of array arr
- }
- (*n) -= n_odd; // we decrease the number of array elements by n_odd odd elements
- // reallocate sufficient space, reallocating memory size of array arr for n_odd elements less
- arr = (int *)realloc( arr, (size_t)( *n ) * sizeof(int) );
- if( arr == NULL ) {
- fprintf(stderr, "\n\n arr realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- return arr;
- } // del_odd_array_elements()
- // Deletes even elements in array arr with n elements
- int *del_even_array_elements(int *arr, int *n){
- int i=0, j=0, n_even=0;
- while( i < (*n) ) { // for all n elements of array arr
- if( *(arr+i)%2 == 0 ) // if that element is even,
- n_even++; // count even elements
- else{
- *(arr+j) = *(arr+i); // put it in the array
- j++; // prepare index for the next array element
- }
- i++; // the next element of array arr
- }
- (*n) -= n_even; // we decrease the number of array elements by n_even even elements
- // reallocate sufficient space, reallocating memory size of array arr for n_even elements less
- arr = (int *)realloc( arr, (size_t)( *n ) * sizeof(int) );
- if( arr == NULL ) {
- fprintf(stderr, "\n\n arr realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- return arr;
- } // del_even_array_elements()
- // Deletes all elements in array arr with n elements
- int *del_all_array_elements(int *arr, int *n){
- (*n) = 0; // there i no elements in array arr
- // reallocate sufficient space, reallocating memory size of array arr for 1 element (can't be 0 elements)
- arr = (int *)realloc( arr, (size_t)( 1 ) * sizeof(int) );
- if( arr == NULL ) {
- fprintf(stderr, "\n\n arr realloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- return arr;
- } // del_even_array_elements()
- // The auxiliary sort function replaces xp and yp with each other
- void swap(int *xp, int *yp){
- int temp = *xp;
- *xp = *yp;
- *yp = temp;
- } // swap()
- // Bubble sort sorts array arr of n elements in ascending order
- void sort_array_ascending(int *arr, int n){
- int i, j;
- for(i=0; i<n-1; i++)
- for(j=0; j<n-1-i; j++) // Last i elements are already in place
- if( arr[j] > arr[j+1] ) // the only difference is in the sign '<' or '>'
- swap( &arr[j], &arr[j+1] );
- } // sort_array_ascending()
- // Bubble sort sorts array arr of n elements in descending order
- void sort_array_descending(int *arr, int n){
- int i, j;
- for(i=0; i<n-1; i++)
- for(j=0; j<n-1-i; j++) // Last i elements are already in place
- if( arr[j] < arr[j+1] ) // the only difference is in the sign '<' or '>'
- swap( &arr[j], &arr[j+1] );
- } // sort_array_descending()
- // Sums the n elements of the array and returns that sum
- float get_array_sum(int *arr, int n){
- int i;
- float sum=0;
- for(i=0; i<n; i++)
- sum += (*arr+i);
- return sum;
- } // get_array_sum()
- // Returns mean value of array arr with n elements.
- // Mean and average are the same.
- // Mean of an array = (sum of all elements) / (number of elements)
- float get_array_mean(int *arr, int n){
- int i;
- float sum=0;
- for(i=0; i<n; i++)
- sum += (*arr+i);
- return (sum/n);
- } // get_array_mean()
- // Returns median of n array arr elements.
- // Median of a sorted array of size n is defined as
- // the middle element when n is odd and
- // average of middle two elements when n is even.
- // Since the array is not sorted here, we sort the array first, then apply above formula.
- float get_array_median(int *arr, int n){
- // First we sort the array
- sort_array_ascending(arr, n);
- // check for even case
- if ( n%2 != 0 )
- return (double)arr[ n/2 ];
- return (double)( arr[ (n-1)/2 ] + arr[ n/2] ) / 2.0;
- } // get_array_median()
- int main(void){
- int *arr1, *arr2; // pointers to two arrays of integers arr1 and arr2
- int n1, n2; // and their numbers of elements
- arr1 = (int*)malloc( n1*sizeof(int) ); // allocate sufficient space
- if( arr1 == NULL ) {
- fprintf(stderr, "\n\n arr1 malloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- arr2 = (int*)malloc( n2*sizeof(int) ); // allocate sufficient space
- if( arr2 == NULL ) {
- fprintf(stderr, "\n\n arr2 malloc() error! \n\n");
- exit(EXIT_FAILURE);
- }
- printf("\n\n ------- arrcpy(arr1, &n1, arr2, n2) -------------------- \n\n");
- fill_and_print_two_arrays_with_integers( arr1, &n1, 5, 1,
- arr2, &n2, 4, 6 );
- arrcpy( arr1, &n1, arr2, n2 );
- printf("\n arrcpy(arr1, &n1, arr2, n2) \n");
- printArray("\n After, arr1 = ", arr1, n1);
- printArray("\n After, arr2 = ", arr2, n2);
- printf("\n\n ------- arrcat(arr1, &n1, arr2, n2) -------------------- \n\n");
- fill_and_print_two_arrays_with_integers( arr1, &n1, 5, 1,
- arr2, &n2, 4, 6 );
- arrcat( arr1, &n1, arr2, n2 );
- printf("\n arrcat(arr1, &n1, arr2, n2) \n");
- printArray("\n After, arr1 = ", arr1, n1);
- printArray("\n After, arr2 = ", arr2, n2);
- printf("\n\n ------- arr_find_num(arr1, n1, 3) ---------------------- \n\n");
- fill_two_arrays_with_integers( arr1, &n1, 5, 1,
- arr2, &n2, 4, 6 );
- printArray("\n arr1 = ", arr1, n1);
- printf("\n Number %d has index %d \n", 3, arr_find_num(arr1, n1, 3) );
- printf("\n\n ------- arr_find_subarr(arr1, n1, arr2, n2) ------------ \n\n");
- fill_and_print_two_arrays_with_integers( arr1, &n1, 9, 1,
- arr2, &n2, 3, 5 );
- printf("\n In arr1 subarray arr2 begin at index %d \n", arr_find_subarr(arr1, 9, arr2, 3) );
- printf("\n\n --- insert_num_into_array(arr1, &n1, num, pos_index) --- \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 5, 1 );
- insert_num_into_array(arr1, &n1, 9, 2);
- printArray("\n After insert_num_into_array(arr1, &n1, 9, 2) \n\n", arr1, n1);
- printf("\n\n --insert_arr2_into_arr1(arr1, &n1, arr2, n2, pos_index)-- \n\n");
- fill_and_print_two_arrays_with_integers( arr1, &n1, 5, 1,
- arr2, &n2, 3, 6 );
- insert_arr2_into_arr1(arr1, &n1, arr2, n2, 2);
- printArray("\n After insert_arr2_into_arr1(arr1, &n1, arr2, n2, 2) \n\n", arr1, n1);
- printf("\n\n -- del_array_element_at_pos_index(arr1, &n1, pos_index)-- \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 9, 1 );
- del_array_element_at_pos_index(arr1, &n1, 3);
- printArray("\n After del_array_element_at_pos_index(arr1, &n1, 3) \n\n", arr1, n1);
- printf("\n\n ----- del_subarray_into_array(arr1, &n1, arr2, n2 ) ----- \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 9, 1 );
- fill_and_print_array_with_integers( arr2, &n2, 3, 5 );
- del_subarray_into_array(arr1, &n1, arr2, n2);
- printArray("\n After del_subarray_into_array(arr1, &n1, arr2, n2) \n\n", arr1, n1);
- printf("\n\n ----------- del_odd_array_elements(arr1, &n1) ----------- \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 9, 1 );
- del_odd_array_elements(arr1, &n1);
- printArray("\n After del_odd_array_elements(arr1, &n1) \n\n", arr1, n1);
- printf("\n\n ----------- del_even_array_elements(arr1, &n1) ---------- \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 9, 1 );
- del_even_array_elements(arr1, &n1);
- printArray("\n After del_even_array_elements(arr1, &n1) \n\n", arr1, n1);
- printf("\n\n ----------- del_all_array_elements(arr1, &n1) ----------- \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 9, 1 );
- del_all_array_elements(arr1, &n1);
- printArray("\n After del_all_array_elements(arr1, &n1) \n\n", arr1, n1);
- printf("\n\n ----------- sort_array_descending(arr1, &n1) ------------ \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 9, 1 );
- sort_array_descending(arr1, n1);
- printArray("\n After sort_array_descending(arr1, n1) \n\n", arr1, n1);
- sort_array_ascending(arr1, n1);
- printArray("\n After sort_array_ascending(arr1, n1) \n\n", arr1, n1);
- printf("\n\n ----------- get_array_sum(arr1, n1) --------------------- \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 9, 1 );
- printf("\n get_array_sum(arr1, n1) = %f \n\n", get_array_sum(arr1, n1) );
- printf("\n\n ----------- get_array_mean(arr1, n1) -------------------- \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 9, 1 );
- printf("\n get_array_mean(arr1, n1) = %f \n\n", get_array_mean(arr1, n1) );
- printf("\n\n ----------- get_array_median(arr1, n1) ------------------ \n\n");
- fill_and_print_array_with_integers( arr1, &n1, 9, 1 );
- printf("\n get_array_median(arr1, n1) = %f \n\n", get_array_median(arr1, n1) );
- fill_and_print_array_with_integers( arr1, &n1, 8, 1 );
- printf("\n get_array_median(arr1, n1) = %f \n\n", get_array_median(arr1, n1) );
- printf("\n\n --------------------------------------------------------- \n\n");
- free(arr1); // freeing up memory because we used malloc()
- free(arr2);
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement