Write a C++ program that inputs three integers from the user and prints the smallest and largest of these numbers.
#include <iostream>
using namespace std;
int main()
{
int numbers[3];
cout<<"Enter 3 integers:";
for(int i =0;i<3;i++){
cin>>numbers[i];
}
int smallest = numbers[0];
int biggest = numbers[0];
for(int i=0;i<3;i++){
if(numbers[i]<smallest) smallest=numbers[i];
if(numbers[i]>biggest) biggest=numbers[i];
}
cout<<"The biggest:"<<biggest<<endl;
cout<<"The smallest:"<<smallest<<endl;
return 0;
}
Comments
Leave a comment