fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int arr[] = {1, 2, 3, 4, 5};
  5. int n = 5;
  6.  
  7. printf("even index elements:\n");
  8. for(int i = 0; i < n; i += 2) {
  9. printf("%d ", arr[i]);
  10. }
  11.  
  12. printf("\nodd index elements:\n");
  13. for(int i = 1; i < n; i += 2) {
  14. printf("%d ", arr[i]);
  15. }
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
even index elements:
1 3 5 
odd index elements:
2 4