Javatpoint Logo
Javatpoint Logo

11. C program to print the number of elements present in an array

Arrays in C are declared as

"sizeof" operator gives the size of the array in bytes so, to get the length of the array we divide the size of the array with the size of the first element.

In this program, we need to count and print the number of elements present in the array.

A number of elements present in the array can be found by calculating the length of the array.

C program to print the number of elements present in an array

Length of above array is 5. Hence, the number of elements present in the array is 5.

ALGORITHM:

  • STEP 1: START
  • STEP 2: INITIALIZE arr[] = {1, 2, 3, 4, 5}
  • STEP 3: length= sizeof(arr)/sizeof(arr[0])
  • STEP 4: PRINT "Number of elements present in given array:" by assigning length.
  • STEP 5: RETURN 0.
  • STEP 6: END

PROGRAM:

Output:

Number of elements present in given array: 5
Next TopicC Programs




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA