Question

Write a C++ function that prints an array, skipping over a number of elements. Use the...

Write a C++ function that prints an array, skipping over a number of elements. Use the following header:

void printArraySkip(int array[], int elems, int skip) {
}

Where 'array' is an input array of 'elem' integer elements, and 'skip' is the number of elements to skip over. For example, if the function is called like this:

int array[6] = { 5, 7, 11, 12, 18, 19 };
printArraySkip(array, 6, 2);

The output would be:

11 19

in c++. Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void printArraySkip(int array[], int elems, int skip) {
    for (int i = skip; i < elems; i++) {
        cout << array[i] << " ";
        i += skip;
    }
    cout << endl;
}

int main() {
    int array[6] = {5, 7, 11, 12, 18, 19};
    printArraySkip(array, 6, 2);
    return 0;
}

11 19 Process finished with exit code O

Add a comment
Know the answer?
Add Answer to:
Write a C++ function that prints an array, skipping over a number of elements. Use the...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • Write a function with two input parameters: an array of numbers and the size of the...

    Write a function with two input parameters: an array of numbers and the size of the array (the number of elements). The function should return the count of even numbers in the array. For example, if the input to the function is the array [3, 2, 45, 56, 12], the function would return the integer 3. Use the following function header: int countEvens(int nums[], int size) { }

  • Consider the following program that reads a number of nonnegative integers into an array and prints...

    Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array.   Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...

  • Assignment: Write a C function that accepts the pointer to a matrix of integer numbers (i.e....

    Assignment: Write a C function that accepts the pointer to a matrix of integer numbers (i.e. a two-dimensional array), number of rows and number of columns as input and prints the matrix after rotating it 90 degrees clockwise. Example: void rotate-matrix (int* matrix, int row, int column) Inputs: row 4, column-6 and the pointer to the matrix below: 2 3 6 5 8 0 Output:

  • Given an integer array a[ ] of N elements. Please write an OpenMP function to sort...

    Given an integer array a[ ] of N elements. Please write an OpenMP function to sort it by the Quicksort algorithm using the task directive. The function header is: void quicksort(int *a, int p, int r). (p represents the start index and r represents the end index)

  • Write a c program that finds the uncommon elements from two array elements using pointers only...

    Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...

  • C++ 3. Random modification of all elements in an integer array. a) Initialize an integer array...

    C++ 3. Random modification of all elements in an integer array. a) Initialize an integer array of capacity 5. b) Implement an array output function. c) Output the array to console. d) Implement an offset function that accepts an integer array as input and randomly modifies each element by +/- 5. e) Use the offset function to update the array. f) Output the modified array. Example Output (input in bold) Original: 5 1 4 9 2 Offset: 7 -2 6...

  • Write a value-returning C++ function returns the average length of an array of strings. Name the...

    Write a value-returning C++ function returns the average length of an array of strings. Name the function stringsAverageLength and use the following header: double stringsAverageLength(string array [], int n) { } where the parameter 'array' has 'n' strings and the return value is the average length of all of the strings in the array. For example, if the function is called like this: string cars[3] = { "Toyota", "Ford", "Tesla" }; cout << fixed << setprecision(2) << stringsAverageLength(cars, 3) <<...

  • Write a program to reverse an integer number by using a function called reverse. The program...

    Write a program to reverse an integer number by using a function called reverse. The program reads in an integer number and prints its reverse order. Note that the function receives the number via a pointer, and uses the pointer to write the reverse number on the main function. The function MUST be used AS IS: void reverse(int *n) Language in C Bonus Problem: Number Reverser reverse c Write a program to reverse an integer number by using a function...

  • Write a complete C++ program that constructs an array A of 10 elements of type Student....

    Write a complete C++ program that constructs an array A of 10 elements of type Student. The type Student is a structure of two fields, the first field of type int represents the ID of the student the second field of type float represents the grade of the student. The program contains the following functions: 1- A void function input that enters the elements in the array. 2- A void function output that displays the elements of the array.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT