
Ternary Operator,Prime Number,GCD
Ternary Operator for 3 numbers : Java: class Main { public static void main ( String [] args ) { int a = 10 , b = 5 , c = 8 ; int smallest = ( a < b ) ? ( a < c ? a : c ) : ( b < c ? b : c ); System . out . println ( smallest ); } } Output: Javascript: let a = 10 , b = 55 , c = 80 ; let smallest = ( a < b ) ? ( a < c ? a : c ) : ( b < c ? b : c ); console . log ( smallest ); Output: Python: a = 100 b = 53 c = 18 smallest = a if ( a < b and a < c ) else ( b if b < c else c ) print ( smallest ) Output: Range of prime numbers : FlowChart: Python: no1 = 10 while no1 <= 50 : div = 2 flag = True while div <= no1 // 2 : if no1 % div == 0 : flag = False break div = div + 1 if flag : print ( no1 , " is prime " ) no1 = no1 + 1 Output: JavaScript: let no1 = 10 ; while ( no1 <= 50 ) { let div = 2 ; let flag = true ; while ( div * div <= no1 ) { if ( no1 % div === 0 ) { flag = false ; break ; } div ++ ; } if ( flag && no1 > 1 ) { console . log ( no1 + " is prime " ); } no1 ++ ; } Output: Java: publ
Continue reading on Dev.to Python
Opens in a new tab



