How can I use information from array that will be passed from function?
#include <stdio.h>
double get_number(double[]);
main {
double x, z[100];
char m;
do {
x = get_number[z];
printf("More numbers?");
scanf (" %c", &m);
}
while ((m == 'Y')||(m == 'y'))
}
double get_number(double arr[])
{
printf ("Please enter number : ?");
scanf("%d", &arr);
return arr;
}
For example
when user press couple times Y and filled array with two or three numbers.
How can I operate with those numbers? count them or just show them.
Use a for() loop.
Of course, you need to know the size beforehand. And don’t use scanf() with an array like that, why not have:
Define your array length to be something fixed:
if you need more than that, increase the value or consider using a list structure.
Hope this helps
EDIT
If you want to have a sum, for example, you need to first initialize the array:
Then you get the input:
Then when thats done, just go through the array and sum it up: