Need some assistance on this.

Hello, I want to write a function named printAscending, that will take an int array and the length as its input and output each integer on a line that is greater than the last. If one is smaller it will drop to a new line and continue from there:
input {2, 5, 8, 3, 9, 9, 7}
output:
2, 5, 8
3, 9, 9
7

I'm not sure how to code this. I would need for it to know when to drop to a new line. Some clarification/assistance would be much appreciated.

void printAccending(int my_array[], int i)
{

for (int i = 0; i < 7; i++)

}


int main()
{
int my_array[] = {2, 5, 8, 3, 9, 9, 7};

printAscending(my_array, 7);

system("Pause");
return 0;
}
You want to loop through the entire array, and check each element if it is less than the last. If that condition is true, you output a newline before outputting the number. You're going to need to use if statements in the for-loop of your printAscending function.
he's right. and inside the array you should do like this
1
2
if ( my_array[i-1] > my_array[i] )
cout << endl;

this means if the previous array is greater than the current array then it will drop a newline
Last edited on
Topic archived. No new replies allowed.