Ive been told to put the following code into a function and yet when i try since it is 3 arrays i cant get it to work at all. Any ideas to get me started on this?
I tried using a function like this
Code:
void funct1(int x[], y[], z[]);
{
for (i=0; i<funct1; i++)
return x[i] = i;
return y[i] = i;
return z[i] = i;
}
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x[10], y[15], z[20];
int i, sumx, sumy, sumz;
for (i=0; i<10; i++)
x[i] = i;
for (i=0; i<15; i++)
y[i] = i;
for (i=0; i<20; i++)
z[i] = i;
sumx = 0;
for (i=0; i<10; i++)
sumx = sumx + x[i];
sumy = 0;
for (i=0; i<15; i++)
sumy= sumy + y[i];
sumz = 0;
for (i=0; i<20; i++)
sumz = sumz + z[i];
printf ("The sum of the x array = %d\n", sumx);
printf ("The sum of the y array = %d\n", sumy);
printf ("The sum of the z array = %d\n", sumz);
system("PAUSE");
return 0;
}
It works fine with no function but im told a function would make it easier to read and faster to process although it seems pretty fast to me.
I'm new to C and working through a workbook and don't understand functions real well yet.
Thank you for any assistance.