One function to display an array and another function to multiply each element of an array by a given value - C Function

C examples for Function:Function Parameter

Description

One function to display an array and another function to multiply each element of an array by a given value

Demo Code

#include <stdio.h>
#define SIZE 5/* w  w  w  . j a  v  a 2s. c om*/

void show_array(const double ar[], int n);
void mult_array(double ar[], int n, double mult);

int main(void){
    double dip[SIZE] = {201.10, 117.616, 18.12, 151.311, 212.212};
    
    show_array(dip, SIZE);
    mult_array(dip, SIZE, 2.5);
    printf("The dip array after calling mult_array():\n");
    show_array(dip, SIZE);
    
    return 0;
}

void show_array(const double ar[], int n){
    int i;
    
    for (i = 0; i < n; i++)
        printf("%8.3f ", ar[i]);
    putchar('\n');
}

/* multiplies each array member by the same multiplier */
void mult_array(double ar[], int n, double mult){
    int i;
    
    for (i = 0; i < n; i++)
        ar[i] *= mult;
}

Related Tutorials