In: Computer Science
In C++ Write a function that took in SIZE and array [size] and counted the number of elements >100
Here is the solution for given problem-
#include<iostream>
using namespace std;
//Function for counting elements greater than 100
int count(int size, int arr[]){
//Initializing count to 0
int c=0;
for(int i= 0 ; i < size ; i++){
if(arr[i] > 100){
//Increase count if element is greater than 100
c++;
}
}
//Returning the value of count
return c;
}
//Main function
int main(){
//Creating variable named size
int size;
cout << "Enter size of array\n";
cin >> size;
//Creating an array
int arr[size];
cout << "Enter "<<size<<" elements of array\n";
for(int i = 0 ; i < size ; i++){
cin >> arr[i];
}
cout <<"Number of elements greater than 100 are : " << count(size, arr)<<endl;
return 0;
}
Sample output-