codescracker


c

C Program to Convert Octal to Binary



« Previous Program Next Program »


Octal to Binary Conversion in C

To convert octal number to binary number in C programming, you have to ask to the user to enter the octal number to convert it into binary number to display the equivalent value in binary

C Programming Code to Convert Octal to Binary

Following C program ask to the user to enter any octal number to convert it into binary, then display the result on the screen:

/* C Program - Octal to Binary Conversion */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	long int i=0;
	char octnum[1000];
	printf("Enter any Octal Number : ");
	scanf("%s",octnum);
	printf("Equivalent Binary Value = ");
	while(octnum[i])
	{
		switch(octnum[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",octnum[i]);
				break;
		}
		i++;
	}
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program convert octal to binary

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test