Implement a function named largerThanN that accepts three arguments: an array of type int, the size of the array of type int and an int number n.
The function should display all of the numbers in the array that are greater than the number n.
in the main() function create an array named numbers containing 10 integers : 30,20,50,2,-1,44,3,12,90,32
Ask the user to enter a number.
Call the the function largerThanN and pass the array , the size and the number that user entered.
Sample Output:
Enter a number:
10
The number that are larger than 10 are: 30 20 50 44 12 90 32
#include<iostream>
using namespace std;
void largerThanN(int arr[],int s,int n)
{
for(int i=0;i<s;i++)
{
if(arr[i]>n)
{
cout<<arr[i]<<" ";
}
}
}
int main()
{
int numbers[10]={30,20,50,2,-1,44,3,12,90,32},n,siz;
siz = sizeof(numbers)/sizeof(numbers[0]);
cout<<"Enter a number ";
cin>>n;
cout<<"\nThe number that are larger than "<<n<<" are ";
largerThanN(numbers,siz,n);
return 0;
}
Comments
Leave a comment