95.9k views
2 votes
Write a program whose inputs are three integers, and whose output is the smallest of the three values. Use else-if selection and comparative operators such as '<=' or '>=' to evaluate the number that is the smallest value. If one or more values are the same and the lowest value your program should be able to report the lowest value correctly. Don't forget to first scanf in the users input.

Ex: If the input is: 7 15 3
the output is: 3

You should sketch out a simple flowchart to help you understand the conditions and the evaluations needed to determine what number is the correct answer. This type of tool can help determine flaws in a logical design.

User Jrista
by
4.6k points

1 Answer

5 votes

Answer:

The Program written in C is as follows:

#include <stdio.h>

int main() {

int num1, num2, num3, smallest;

printf("Enter any three numbers: ");

scanf("%d", &num1); scanf("%d", &num2); scanf("%d", &num3);

if(num1 <= num2 && num1 <= num3) {

smallest = num1;

}

else if(num2 <= num1 && num2 <= num3) {

smallest = num2;

}

else {

smallest = num3;

}

printf("Smallest: ");

printf("%d", num3);

return 0;

}

Step-by-step explanation:

This line declares necessary variables

int num1, num2, num3, smallest;

This line prompts user for input of three numbers

printf("Enter any three numbers: ");

This lines get input for the three numbers

scanf("%d", &num1); scanf("%d", &num2); scanf("%d", &num3);

The following if/else statements determine the smallest of num1, num2 and num3 and assigns to variable smallest, afterwards

if(num1 <= num2 && num1 <= num3) {

smallest = num1;

}

else if(num2 <= num1 && num2 <= num3) {

smallest = num2;

}

else {

smallest = num3;

}

The next two lines print the smallest value

printf("Smallest: ");

printf("%d", num3);

User Fathia
by
5.0k points