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.
#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;
}
Comments
Leave a comment