Develop a C function to create an array with 10 float elements and create another
module which calculate the mean of float array.
Answers
Answer:
An array is a group (or collection) of same data types. For example an int array holds the elements of int types while a float array holds the elements of float types.
Why we need Array in C Programming?
Consider a scenario where you need to find out the average of 100 integer numbers entered by user. In C, you have two ways to do this: 1) Define 100 variables with int data type and then perform 100 scanf() operations to store the entered values in the variables and then at last calculate the average of them. 2) Have a single integer array to store all the values, loop the array to store all the entered values in array and later calculate the average.
Which solution is better according to you? Obviously the second solution, it is convenient to store same data types in one single variable and later access them using array index (we will discuss that later in this tutorial).