Author : Rahul
Write a program to convert octal number to decimal number
Program
using System;
namespace ProgrammingQuestion
{
class Program
{
static void Main(string[] args)
{
//Variable Declaration
string octalNumberVal;
int octalNumber, decimalNumber = 0, tempNumber, digit, power = 0;
//User Input
Console.Write("Enter Octal Number:");
octalNumberVal = Console.ReadLine();
octalNumber = Convert.ToInt32(octalNumberVal);
//Octal to Decimal Logic
tempNumber = octalNumber;
while (tempNumber > 0)
{
digit = tempNumber % 10;
decimalNumber = decimalNumber + digit * (int)Math.Pow(8, power);
power++;
tempNumber = tempNumber / 10;
}
//Print Result
Console.WriteLine($"Decimal Number: {decimalNumber}");
Console.Read();
}
}
}
Output
Enter Octal Number:3456
Decimal Number: 1838