C Program to Convert Octal to Binary

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    long int i=0;
    char octal_num[1000];
    printf("\n Enter any Octal Number : ");
    scanf("%s",octal_num);
    printf("\n Equivalent Binary Value = ");
    while(octal_num[i])
    {
        switch(octal_num[i])
        {
            case '0' : printf("000");
                break;
            case '1' : printf("001");
                break;
            case '2' : printf("010");
                break;
            case '3' : printf("011");
                break;
            case '4' : printf("100");
                break;
            case '5' : printf("101");
                break;
            case '6' : printf("110");
                break;
            case '7' : printf("111");
                break;
            default : printf("\nInvalid Octal Digit %c",octal_num[i]);
                break;
        }
        i++;
    }
    getch();
}

Run1:
Run2:


No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...