+ 1

How to count element of array from input in c language?

Example I define int arr[100], but when I input array in scanf, I put only 5 element (example : 7,4,7,3,8). How I count the element, so the output is 5? If I use sizeof, the output is become 100.

28th Oct 2020, 11:14 AM
Briana
Briana - avatar
4 Respuestas
+ 3
You can already count the elements while they are being inputted or you already know how many times to ask for input ,
28th Oct 2020, 11:25 AM
Abhay
Abhay - avatar
+ 2
Briana yes
28th Oct 2020, 11:32 AM
Abhay
Abhay - avatar
+ 1
Briana You can use a counter for the dupes and then print the total of all the numbers read minus the total of the dupes. https://code.sololearn.com/c0z7H4AeVWMq/?ref=app
28th Oct 2020, 12:32 PM
Davide
Davide - avatar
0
Abhay I know.. But, I want to count the same element as one. So, if I scanf 8,5,3,7,8 example, the output is 4. Shouldn't I count the whole elements first?
28th Oct 2020, 11:28 AM
Briana
Briana - avatar