+ 2

How do I correct my code?

I just started learning arrays in c language...so I'm kind of experimenting. I tried making a code that searches for the first number of an array. What do you think is wrong? Please help. https://code.sololearn.com/cttLKrL04g53/?ref=app

25th Oct 2021, 12:18 PM
Leoror
Leoror - avatar
2 Respuestas
+ 1
I’m not sure if I’m understanding you, in your code you have 2 variables: n and first, but after scanning you are not using “n” at all. First is also an integer variable but you wrote it like (10 17 45 92..) So it makes me think that you’re trying to use it as an array right? If you want First to be an array of integers you should declare it as int first[number of elements] = {10, 17, 45, 92, 56…. The rest of the numbers} If you only want the first element of the array you could do printf(“First digit = %d”, first[0]) If you want to search value of n inside the first array then you should think how to change your while loop :p
25th Oct 2021, 12:50 PM
Guillem Padilla
Guillem Padilla - avatar
+ 1
Guillem Padilla oh. I understand it already. Thanks!
25th Oct 2021, 1:28 PM
Leoror
Leoror - avatar