Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
ı could not write anything about this question.Question is under




Please write a C code that prints out ONLY even index elements of the following array.

arr = {5, 2, 6, 10, 4, 18, 3, 4, 7}

What I have tried:

ı searched on google and ı found a code but this code say me while its working "please enter array" ı dont want this.
Posted
Updated 4-May-20 18:39pm

Why on earth are you searching for code for this? DON'T. It won't teach you anything useful.

This is a very simple app. You just define an array and then print every other element of it from inside a for loop.

You would have covered this stuff in your classes.
 
Share this answer
 
Quote:
ı searched on google and ı found a code

As programmer, your job is to create code, just searching on google will not help your to learn anything.
Quote:
ı could not write anything about this question.

You need to reread your lessons and try again, if you can't come up with anything, have a talk with your teacher.
 
Share this answer
 
Dave Kreskowiak gave you the first 1/2 of the answer - use a for loop - so write a for loop, to start with, to print every element

Now, how do you test if a number is even or odd ? think about the 'modulo' operator ie '%' - so change your print statement to only print on even numbers of the for loop index, using '%'
 
Share this answer
 
Comments
CPallini 5-May-20 2:34am    
"Dave Kreskowiak gave you the first 1/2 of the answer"
Because you divided the for loop by 2. :-D
No actual need to use the modulo operator, in such a task.
Garth J Lancaster 5-May-20 2:40am    
;-) yes - I guess if a person can construct a for loop they should be able to figure it out - I was trying to suggest a 'simple' path from a known result

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900