Answer to Question #266592 in C++ for juji

Question #266592

Write a C++ program that takes elements in an array from user. You have to make a function named positive(int) and find total count of positive numbers in an array.


1
Expert's answer
2021-11-15T17:22:01-0500
#include<iostream>
using namespace std;
int positive(){
	cout<<"Enter the number of elements of the array\n";
	int n;
	cin>>n;
	int arr[n];
	int count = 0;
	cout<<"Enter the elements of the array\n";
	for(int i=0; i<n; i++){
		cout<<"Element  "<<(i+1)<<": ";
		cin>>arr[i];
		if(arr[i]>0){
			count ++;
		}
	}
	
	return count;
}


int main(){
	cout<<"The number of positive numbers from the array is: "<<positive()<<endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS