192k views
2 votes
Write a C program that prompts the user to enter three numbers, then finds out and displays the smallest number of the three numbers entered.

User BPX
by
8.1k points

1 Answer

3 votes

Final Answer:

A C program that prompts the user to input three numbers and then determines and displays the smallest among them is provided below:

hashinclude <stdio.h>

int main() {

// Declaration of variables

double num1, num2, num3;

// Prompting the user to input three numbers

printf("Enter three numbers: ");

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

// Finding the smallest number

double smallest = (num1 < num2) ? (num1 < num3 ? num1 : num3) : (num2 < num3 ? num2 : num3);

// Displaying the result

printf("The smallest number is: %lf\\", smallest);

return 0;

}

Step-by-step explanation:

This C program utilizes the scanf function to take user input for three numbers. It then employs a ternary operator to determine the smallest among the three. The result is displayed using printf. This code showcases basic input and output operations in C, along with conditional statements.

Note: Symbol is not used. Hash is return. Because there is an issue in uploading.

User Johnny Graber
by
9.0k points