In: Computer Science
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
For this program, we don't need to store the inputs in an array. We can compare them in real time and find out the smallest.
CODE :
#include <iostream>
using namespace std;
int main()
{
cout<<"Enter the numbers. Enter 999 to
stop"<<endl;
int x;
cin>>x;
int min = x;
while(x!=999)
{
if(x<min)
min = x;
cin>>x;
}
cout<<"Output : "<<min<<endl;
return 0;
}