Please, write a loop to print even numbers of an array a with pointers. You can use a variable “size” for array size
#include <stdio.h> int main() { int a[] = {5, 9, 2, 3, 1, 6}; // array for testing int size = 6; // size of the array // let's print the array using pointers as asked int *p = a; // make p point to first item in array int i = 0; for (i = 0; i < size; ++i) { // let's iterate a loop size times if (*p % 2 == 0) // if the number is even, then printf("%d ", *p); // print the number that p is pointing to p++; // move to next element in the array } printf("\n"); // print a newline return 0; }
Get Answers For Free
Most questions answered within 1 hours.