Respuesta :
Answer:
The program to this question as follows:
Program:
#include<iostream> //include header file.
using namespace std; //using name space.
int main() //main function.
{
int n,i,key; //define variable.
int a[n]; //define array
cout<<"Enter size of array :"; //message.
cin>>n; //input number from user.
cout<<"Enter array elements :"; //message
for(i = 0;i<n;i++) //loop
{
cin>>a[i]; //input array elements
}
cout<<"Enter a number:"; //message
cin>>key; //input number.
for(i = 0;i<n;i++) //loop
{
if(a[i]<=key) //if block
{
cout<<a[i]<<"\n "; //print array elements
}
}
return 0;
}
Output:
Enter size of array :7
Enter array elements :5
50
50
75
100
200
140
Enter a number:100
5
50
50
75
100
Explanation:
The description of the above program as follows:
- In this program first, we include a header file and define the main method in method we define variables and array that are "n, i, key and a[]". In this function, all variable data type is "integer".
- The variable n is used for the size of array and variable i use in the loop and the key variable is used for comparing array elements. Then we use an array that is "a[]" in the array, we use the for loop to insert elements form user input.
- Then we define a loop that uses a conditional statement in if block we check that array elements is less than and equal to a key variable. If this value is true so, we will print the remaining elements.