Write a program that uses a for statement to find the smallest of several integers. Assume that the first value read specifies the number of values remaining and that the first number is not one of the integers to compare.
in C++, thanks a lot
C++ program help, please?
What do you have so far?
Reply:# include %26lt;iostream%26gt;
using namespace std;
int main()
{
int desired, number, smallest;
cout %26lt;%26lt; "Enter the desired number of integers to compare: ";
cin %26gt;%26gt; desired;
for( int i=0; i %26lt; desired; i++ )
{
cout %26lt;%26lt; "Enter number to compare: ";
cin %26gt;%26gt; number;
if( i == 0 )
smallest = number;
else if ( number %26lt; smallest )
smallest=number;
}
cout %26lt;%26lt; "The smallest is " %26lt;%26lt; smallest %26lt;%26lt; endl;
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment