C Program
/* C - Convert Octal to Decimal */ #include <stdio.h> #include <math.h> int main(){ long long oct; scanf("%lld",&oct); long long dec=0, base=1; while(oct>0){ int d = oct%10; dec += d*base; base *= 8; oct /= 10; } printf("%lld", dec); return 0; }
C Output
Input: 157 Output: 111
C++ Program
// C++ - Convert Octal to Decimal #include <bits/stdc++.h> using namespace std; int main(){ long long oct; cin>>oct; long long dec=0, base=1; while(oct>0){ int d = oct%10; dec += d*base; base *= 8; oct /= 10; } cout<<dec; }
C++ Output
Input: 245 Output: 165
JAVA Program
// Java - Convert Octal to Decimal import java.util.*; class Main{ public static void main(String[] args){ Scanner s = new Scanner(System.in); long oct = s.nextLong(), dec = 0, base = 1; while(oct > 0){ long d = oct % 10; dec += d * base; base *= 8; oct /= 10; } System.out.print(dec); } }
JAVA Output
Input: 10 Output: 8
Python Program
# Python - Convert Octal to Decimal octal = int(input()) decimal, base = 0, 1 while octal > 0: d = octal % 10 decimal += d * base base *= 8 octal //= 10 print(decimal)
Python Output
Input: 77 Output: 63
In-Depth Learning – Entire Concept in Paragraphs
Social Plugin