160k views
0 votes
int myArray-11,3,-8,30,-2,0,5,7,-100,44); Write a loop statement to display the positive numbers each on a separate line like this: 30

User Stdcerr
by
5.7k points

1 Answer

4 votes

Answer:

#include <iostream>

using namespace std;

int main()

{

int myArray[] = {-11,3,-8,30,-2,0,5,7,-100,44};

int n = sizeof(myArray)/sizeof(myArray[0]);

for(int i=0;i<n;i++){

if(myArray[i]>=0){

cout<<myArray[i]<<endl;

}

}

return 0;

}

Step-by-step explanation:

First include the library iostream in c++ programming for using the input/output function.

Then, create the main function and define the array with the elements which contain both positive element as well negative elements.

after, use the for loop for traversing the array and inside the loop take the conditional statement for check if element in the array is positive.. if it true then print the element on the screen with separate line.

User Satish Patro
by
5.6k points