
Basic Programs in Python,Java & JavaScript: Smallest Number, Prime Number, and GCD
Finding the Smallest Number Among Three Using Ternary Operator What is a Ternary Operator? A ternary operator is a shorthand way of writing an if-else condition in a single line. Syntax: condition ? value_if_true : value_if_false; JavaScript Code let a = 5 , b = 2 , c = 8 ; let smallest = ( a < b && a < c ) ? a : (( b < c ) ? b : c ) console . log ( " Smallest number is: " ) Python Code a = int ( input ( " Enter number 1: " )) b = int ( input ( " Enter number 2: " )) c = int ( input ( " Enter number 3: " )) smallest = a if ( a < b and a < c ) else ( b if b < c else c ) print ( " Smallest number is: " , smallest ) Java Code public class SmallestNumber { public static void main ( String [] args ) { int a = 5 , b = 2 , c = 8 ; int smallest = ( a < b && a < c ) ? a : (( b < c ) ? b : c ); System . out . println ( "Smallest number is: " + smallest ); } } Output How to find prime numbers within a given range A prime number is a number greater than 1 that has only two factors: 1 and itself Ex
Continue reading on Dev.to Python
Opens in a new tab


