Problem statement:- Program to convert octal to decimal.
Data requirement:-
Input Data:- octal
Output Data:-decimal
Output Data:-decimal
Program in C
Here is the source code of the C Program to convert octal to decimal.
Code:
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
Program in C++
Here is the source code of the C++ Program to convert octal to decimal.
Code:
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
Program in Java
Here is the source code of the Java Program to convert octal to decimal.
Code:
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
Program in Python
Here is the source code of the Java Program to convert octal to decimal.
Code:
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)
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
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box