216k views
18 votes
3.21 LAB: Smallest number

Write a program whose inputs are three integers, and whose output is the smallest of the three values C++

User Hjord
by
5.6k points

1 Answer

10 votes

Answer:

#include <iostream>

using namespace std;

int main(){

int a, b, c;

cout<<"Enter three integers: ";

cin>>a>>b>>c;

if(a<=b && a<=c){

cout<<"Smallest: "<<a; }

else if(b<=a && b<=c){

cout<<"Smallest: "<<b; }

else{

cout<<"Smallest: "<<c; }

return 0;

}

Step-by-step explanation:

This line declares three integer variables a, b and c

int a, b, c;

This line prompts the user for three integer inputs

cout<<"Enter three integers: ";

This line gets the inputs

cin>>a>>b>>c;

This checks if the first is the smallest

if(a<=b && a<=c){

If yes, it prints the first as the smallest

cout<<"Smallest: "<<a; }

This checks if the second is the smallest

else if(b<=a && b<=c){

If yes, it prints the second as the smallest

cout<<"Smallest: "<<b; }

If the above conditions are not true, then the third number is printed as the smallest

else{

cout<<"Smallest: "<<c;

}

User Vicatcu
by
5.5k points