C program to convert octal into binary.

 

01  #include<stdio.h>
02 #define MAX 1000
03
04 int main()
05 {
06 char octalNumber[MAX];
07 long int i=0;
08
09 printf("Enter any Octal number : ");
10 scanf("%s",octalNumber);
11
12 printf("Binary value : ");
13
14 while(octalNumber[i])
15 {
16 switch(octalNumber[i])
17 {
18 case '0': printf("000"); break;
19 case '1': printf("001"); break;
20 case '2': printf("010"); break;
21 case '3': printf("011"); break;
22 case '4': printf("100"); break;
23 case '5': printf("101"); break;
24 case '6': printf("110"); break;
25 case '7': printf("111"); break;
26 default: printf("nInvalid octal digit %c ",octalNumber[i]); return ;
27 }//end of switch
28
29 i++;
30
31 }//end of loop
32
33 return 0;
34 }
 
 
OUTPUT :

Enter any Octal number : 12
Binary value : 001010

Related Post

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.