Write a function (sequence low high stride) that takes three arguments low, high, and stride, all assumed to be numbers. Further assume stride is positive. The function produces a list of numbers from low to high (including low and possibly high) separated by stride and in sorted order.

Respuesta :

Answer:

// Program is written in C++ programming language

// Comments are used for explanatory purpose

// Program starts here

#include <iostream>

using namespace std;

int main()

{

// Prompt to enter values for low, high and stride

cout<<"Low : ";

cin>>a;

cout<<"High : ";

cin>>b;

cout<<"Stride : ";

cin>>c;

// Check if sequence has an end

If(c>0 && b>a)

{

// Call sequence function to print values

sequence(a,b,c);

}

else

{

cout<<"Unable to print sequence";

}

return 0;

}

// Sequence function is defined here

void sequence(int low, int high, int stride )

{

// Iterate from low to high with a difference of stride

for(int i = low; i<= high; I+=stride;)

cout<<i<<endl;

}

ACCESS MORE