Sunday, 15 December 2013

C Program to Convert Octal to Binary

#include < stdio.h>
#define MAX 1000

int main()
{
char octalnum[MAX];
long i = 0;

printf("Enter any octal number: ");
scanf("%s", octalnum);
printf("Equivalent binary value: ");
while (octalnum[i])
{
switch (octalnum[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("\n Invalid octal digit %c ", octalnum[i]);
return 0;
}
i++;
}
return 0;
}

Output

 Enter any octal number: a
Equivalent binary value:
Invalid octal digit a


Enter any octal number: 160
Equivalent binary value: 001110000

For More Details Please Visit Ictjobs.info

No comments: