Octal to decimal program

octal to decimal in c

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int octalNumber,decimalNumber=0,baseNumber=1,reminder;
printf("Enter the octal number \n");
scanf("%d",&octalNumber);
for(int i=0;octalNumber>0;i++)
{
reminder=octalNumber%10;
octalNumber/=10;
decimalNumber+=reminder*pow(8.0,i);
}
printf("Its equivalent decimal number is = %d",decimalNumber);
getch();
}

Output

Enter the octal number
12
Its equivalent decimal number is = 10

octal to decimal in c++

#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
void main()
{
int octalNumber,decimalNumber=0,baseNumber=1,reminder;
cout<<"Enter the octal number \n";
cin>>octalNumber;
for(int i=0;octalNumber>0;i++)
{
reminder=octalNumber%10;
octalNumber/=10;
decimalNumber+=reminder*pow(8.0,i);
}
cout<<"Its equivalent decimal number is = "<<decimalNumber;
getch();
}

Output

Enter the octal number
24
Its equivalent decimal number is = 20

octal to decimal in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConvertOctalToDecimal
{
class Program
{
static void Main(string[] args)
{
int octalNumber, decimalNumber = 0, reminder,baseNumber=8;
Console.WriteLine("Enter the octal number");
for (int i = 0; octalNumber > 0; i++)
{
reminder = octalNumber % 10;
octalNumber /= 10;
decimalNumber +=Convert.ToInt32( reminder * Math.Pow(Convert.ToDouble(baseNumber),Convert.ToDouble(i)));
}
Console.WriteLine("Its equivalent decimal number is = "+ decimalNumber);
}
}
}

Output

Enter the octal number
65
Its equivalent decimal number is = 53

octal to decimal in java

import java.util.*;
class examples
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int octalNumber, decimalNumber = 0, reminder,baseNumber=8;
System.out.println("Enter the octal number");
octalNumber=sc.nextInt();
for (int i = 0; octalNumber > 0; i++)
{
reminder = octalNumber % 10;
octalNumber /= 10;
decimalNumber +=(int)( reminder * Math.pow((double)baseNumber,(double)i));
}
System.out.println("Its equivalent decimal number is = "+ decimalNumber);
}
}

Output

Enter the octal number
62
Its equivalent decimal number is = 50

Write a comment

Name Email Message