human
Ternary number system or Base 3 numbers | Function to convert a decimal number to a ternary number.
Base case.
Finding the remainder when N is divided by 3.
Recursive function to call the function for the integer division of the value N / 3.
Handling the negative cases.
Function to convert the decimal to ternary.
If the number is greater than 0 , compute the ternary representation of the number.
Driver Code"
Solution in Python:
assistant
#Here is code to ternary number system or Base 3 numbers and the other steps required.
 def convertToTernary ( N ) :
	if ( N == 0 ) :
		return ;
	x = N % 3 ;
	N //= 3 ;
	if ( x < 0 ) :
		N += 1 ;
	convertToTernary ( N ) ;
	if ( x < 0 ) :
		print ( x + ( 3 * - 1 ) , end = " " ) ;
	else :
		print ( x , end = " " ) ;
def convert ( Decimal ) :
	print ( " Ternary ▁ number ▁ of ▁ " , Decimal , " ▁ is : ▁ " , end = " " ) ;
	if ( Decimal != 0 ) :
		convertToTernary ( Decimal ) ;
	else :
		print ( "0" , end = " " ) ;
if __name__ == ' _ _ main _ _ ' :
	Decimal = 2747 ;
	convert ( Decimal ) ;