Question

Please, write a loop to print even numbers of an array a with pointers. You can...

Please, write a loop to print even numbers of an array a with pointers. You can use a variable “size” for array size

Homework Answers

Answer #1
#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a loop to print an array a with pointers backwards. You can use a variable...
write a loop to print an array a with pointers backwards. You can use a variable “size” for array size. write you code in C
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Create an array named data that can store 100 integers. Write a for loop that loops...
Create an array named data that can store 100 integers. Write a for loop that loops 100 times. Inside the loop store the variable you are using to increment the loop into the current element of the array data. So the array data should have a 0 at index 0, a 1 at index 1, a 2 at index 2, ..., a 99 at index 99.
1- Write a program to print only the even numbers from 100 to 200 2- Write...
1- Write a program to print only the even numbers from 100 to 200 2- Write a program to print the odd numbers from 22 – 99 3- Write a program to calculate howe many even number from 10 to 120 1- Write a program to find only the even numbers for 12 different numbers 2- Write a program to find the odd numbers for 10 different numbers 3- Write a program to calculate howe many even number and how...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
Using a for loop and range command, print the sequence of numbers from 1 to 20...
Using a for loop and range command, print the sequence of numbers from 1 to 20 (skipping two numbers for each element); that is, your code should print out the numbers 1,4, 7, 10, … (max should not exceed 20). Use x as the variable name
Write an R code to print out all even numbers from the following numbers list in...
Write an R code to print out all even numbers from the following numbers list in the same order they are received. Write the code so it does not print any numbers that come after 83. numbers = [951, 40, 84, 51, 60, 69, 48, 19, 61, 85, 98, 50, 72, 47, 44, 61, 83, 65, 41, 51, 63, 61, 65, 75, 21, 30, 84, 92, 23]
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
create an array and fill it in with even numbers. use c++
create an array and fill it in with even numbers. use c++