C examples for Function:Function Definition
Create function to accept two arrays with the same size, add each element in the arrays together and place the values in a third array.
#include <stdio.h> #define SIZE 10/*www . ja v a 2 s . com*/ void addarrays( int first[], int second[]) { int total[SIZE]; int *ptr_total = &total[0]; int ctr = 0; for (ctr = 0; ctr < SIZE; ctr ++ ) { total[ctr] = first[ctr] + second[ctr]; printf("%d + %d = %d\n", first[ctr], second[ctr], total[ctr]); } } int main( void ){ int a[SIZE] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; int b[SIZE] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; addarrays(a, b); return 0; }