C Program To Convert Decimal To Octal Number In One Line


Lets write a C program to convert a number from Decimal number system(base 10) to Octal number system(base 8) in one line.

Related Read:
C Program To Convert Decimal Number To Octal Number, using While Loop

Expected Output for the Input

User Input:
Enter a Decimal Number
90

Output:
Octal representation of Decimal number 90 is 132

Logic To Convert Decimal To Octal Number In One Line of Code

In c programming language, any decimal number you store will also be stored in Octal form and you can print it using %o format specifier.

Video Tutorial: C Program To Convert Decimal To Octal Number In One Line


[youtube https://www.youtube.com/watch?v=41-xLNYbvDY]

YouTube Link: https://www.youtube.com/watch?v=41-xLNYbvDY [Watch the Video In Full Screen.]

Source Code: C Program To Convert Decimal To Octal Number In One Line

#include < stdio.h >

int main()
{
    int num;

    printf("Enter a Decimal Number\n");
    scanf("%d", &num);

    printf("\nOctal representation of Decimal number %d is %o\n", num, num);

    return 0;
}

Output 1:
Enter a Decimal Number
16

Octal representation of Decimal number 16 is 20

Output 2:
Enter a Decimal Number
41

Octal representation of Decimal number 41 is 51

Output 3:
Enter a Decimal Number
90

Octal representation of Decimal number 90 is 132

Output 4:
Enter a Decimal Number
14

Octal representation of Decimal number 14 is 16

Output 5:
Enter a Decimal Number
32

Octal representation of Decimal number 32 is 40

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

Leave a Reply

Your email address will not be published. Required fields are marked *