213k views
5 votes
) Consider the array called myArray declared below that contains and negative integers. Write number of positive integers in the array. That is, your loop display the message "Number of positive integers is 5" a loop statement to count and display the should (4 points) int myArray[]卟1,3,-9,9,33,-4,-5, 100,4,-23); Note: The loop should always work without modification even if the values in th array are changed

User Lela
by
5.0k points

1 Answer

5 votes

Answer:

#include <iostream>

using namespace std;

int main()

{

int arr[]={3,-9,9,33,-4,-5, 100,4,-23};

int pos;

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

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

if(arr[i]>=0){

pos++;

}

}

cout<<"Number of positive integers is "<<pos<<endl;

return 0;

}

Step-by-step explanation:

create the main function in the c++ programming and declare the array with the element. Then, store the size of array by using the formula:

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

after that, take a for loop for traversing the array and then check condition for positive element using if statement,

condition is array element greater than or equal to zero.

if condition true then increment the count by 1.

this process happen until the condition true

and finally print the count.

User Dest
by
5.6k points