Hey all, I'm at the part of my course where I am being taught arrays, and passing them to functions. I have been asked to produce a program that has 2 arrays that the user enters 10 numbers in and then gives the total for each array.
So far i've come up with this :
Code:
#include <stdlib.h>
#include <stdio.h>
#define NUMBER_ELEMENTS 10
void f_enter ();
void f_display ();
void main ()
{
float number[NUMBER_ELEMENTS];
f_enter (number, NUMBER_ELEMENTS);
f_display (number, NUMBER_ELEMENTS) ;
exit(0);
}
void f_enter (int input[], int size)
{
int i = 0 ;
for (i = 0; i < 10; i ++)
{
printf("Enter number %d for first array: ", i + 1);
scanf("%d", &input[i]);
fflush(stdin);
}
}
void f_display (int display[], int number_elements)
{
int i = 0, total = 0 ;
for (i = 0; i < 10; i ++)
{
total = total + display[i];
}
printf("total is %d ", total);
}
This does it for one array, but I really just copied some other code from a book that did something similar and it somehow works. I really don't see how the array is being passed and used in the display function, or how I would do this for a second array.
Is there anyone who can help explain whats going on in the code and how its being passed between f_enter and f_display.