Program to convert octal to decimal

Code:

#include <stdio.h>
#include <math.h>
int
main ()
{
int octal;

printf("Enter the octal number: ");
scanf("%d", &octal);
int decimal = 0, sem = 0;
while(octal!= 0)
{
decimal=decimal+(octal%10)*pow(8,sem);
sem++;
octal=octal/ 10;
}
printf("Decimal number is: %d",decimal);
return 0;
}

Input/Output:
Enter the octal number: 65
Decimal number is: 53

Code:

#include <iostream>
#include <cmath>
using namespace std;
int
main ()
{
int octal;
cout<<"Enter the octal number: ";
cin>>octal;
int decimal = 0, sem = 0;
while(octal!= 0)
{
decimal=decimal+(octal%10)*pow(8,sem);
sem++;
octal= octal/ 10;
}
cout<<"Decimal number is: "<<decimal;
return 0;
}

Input/Output:
Enter the octal number: 73
Decimal number is: 59

Code:

import java.util.Scanner;
public class OctalToDecimal {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int octal;

System.out.println("Enter the octal number: ");
octal=cs.nextInt();
int decimal = 0, sem = 0;
while(octal!= 0)
{
decimal=(int) (decimal+(octal%10)*Math.pow(8,sem));
sem++;
octal= octal/ 10;
}
System.out.println("Decimal number is: "+decimal);

cs.close();
}
}

Input/Output:
Enter the octal number:
703
Decimal number is: 451

Code:

print("Enter the octal number: ");
octal=int(input());
decimal = 0
sem = 0
while(octal!= 0):
decimal=decimal+(octal%10)*pow(8,sem)
sem+=1
octal=octal// 10
print("Decimal number is: ",decimal)

Input/Output:
Enter the octal number:
11
Decimal number is:  9