Returns number of valuesDisplays the number in brackets of return value
C Program to Return the Number of Values
Here is an example of a C program that returns the number of values:
#include <stdio.h>
int countValues(int arr[], int size) {
return size;
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
int size = sizeof(arr) / sizeof(arr[0]);
int count = countValues(arr, size);
printf("The number of values is: %d\n", count);
return 0;
}
Explanation
- The program starts by including the necessary header file
stdio.h
, which provides input and output functions likeprintf
. - The
countValues
function takes an arrayarr
and its sizesize
as parameters. It simply returns the size of the array. - In the
main
function, an arrayarr
is declared and initialized with some values. - The size of the array is calculated by dividing the total size of the array (
sizeof(arr)
) by the size of a single element (sizeof(arr[0])
). - The
countValues
function is called with the array and its size as arguments, and the returned value is stored in thecount
variable. - Finally, the number of values is printed using
printf
.
Note: This program assumes that the array arr
is already populated with values. If you want to input values from the user, you can modify the program accordingly.
I hope this helps! Let me know if you have any further questions.