Lets write a C program to convert a number from Octal number system(base 8) to Decimal number system(base 10) in one line.
Related Read:
C Program To Convert Octal Number To Decimal Number, using While Loop
Page Contents
Expected Output for the Input
User Input:
Enter an Octal number
41
Output:
Decimal Representation of Octal Number 41 is 33.
Logic To Convert Octal To Decimal Number In One Line of Code
In c programming language, any octal number(%o format specifier) you store will also be stored in decimal form and you can print it using %d format specifier.
Video Tutorial: C Program To Convert Octal To Decimal Number In One Line
[youtube https://www.youtube.com/watch?v=ifkQ4wDsE6I]
Source Code: C Program To Convert Octal To Decimal Number In One Line
#include < stdio.h > int main() { int num; printf("Enter an Octal number\n"); scanf("%o", &num); printf("\nDecimal Representation of Octal Number %o is %d\n", num, num); return 0; }
Output 1:
Enter an Octal number
20
Decimal Representation of Octal Number 20 is 16
Output 2:
Enter an Octal number
51
Decimal Representation of Octal Number 51 is 41
Output 3:
Enter an Octal number
132
Decimal Representation of Octal Number 132 is 90
Output 4:
Enter an Octal number
16
Decimal Representation of Octal Number 16 is 14
Output 5:
Enter an Octal number
40
Decimal Representation of Octal Number 40 is 32
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert