Write the function READARRAY with 2 parameters TAB and NMAX reads and returns the dimension N and the components of a table TAB of the type int. The dimension N must be less than NMAX. Implement the function READARRAY by choosing the type of the parameters.

Example:

For a call by

      N=READARRAY(T, 10);

  the function will behave as follows:

   Size of the array (max.10): 11
   Size of the array (max.10): 4
   Element [0]: 43
   Element [1]: 55
   Element [2]: 67
   Element [3]: 79


Difficulty level
Video recording
This exercise is mostly suitable for students
int READARRAY(int TAB[], int NMAX)
{
	int I, N;
	do
	{
		printf("Size of the array (max.%d) : ", NMAX);
		scanf("%d", &N); 
	} while (N<0 || N>NMAX);

	for (I = 0; I<N; I++)
	{
		printf("Element[%d] : ", I);
		scanf("%d", &TAB[I]);
	}
	return N;
}
 

 

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Prim Algorithm - Minimal Spanning Tree