Ternary number system or Base 3 numbers | C # program to convert a ternary number to decimal number ; Function to convert a ternary number to a decimal number ; If the number is greater than 0 , compute the decimal representation of the number ; Loop to iterate through the number ; Computing the decimal digit ; Driver code
using System ; class GFG { static void convertToDecimal ( int N ) { Console . Write ( " Decimal ▁ number ▁ of ▁ " + N + " ▁ is : ▁ " ) ; if ( N != 0 ) { int decimalNumber = 0 ; int i = 0 , remainder ; while ( N != 0 ) { remainder = N % 10 ; N /= 10 ; decimalNumber += remainder * ( int ) Math . Pow ( 3 , i ) ; ++ i ; } Console . Write ( decimalNumber + " STRNEWLINE " ) ; } else Console . Write ( "0" + " STRNEWLINE " ) ; } public static void Main ( ) { int Ternary = 10202202 ; convertToDecimal ( Ternary ) ; } }