Answer to Question #189573 in C++ for Rose

Question #189573

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


1
Expert's answer
2021-05-05T19:29:08-0400
#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;
}

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