In this tutorial we will learn how to write a program that convert binary number to octal number.
C program code
#include<stdio.h>
#include<conio.h>
void main()
{
int octalNum[]={0,1,10,11,100,101,110,111};
long int binary,i,number,temp,octal=0,j=1;
printf("\n Enter Binary number:\n ");
scanf("%ld",&binary);
temp=binary;
while(temp!=0)
{
number=temp%1000;
for(i=0;i<=7;i++)
{
if(octalNum[i]==number)
{
octal=octal+(i*j);
}
}
j*=10;
temp/=1000;
}
printf("\n Octal number for given Binary number %ld is %ld\n",binary,octal);
getch();
}
OUTPUT:
We will enter a binary number.
In this output the value of binary code is 11110
And octal number for this binary number is 36
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.
Created by-- HARSH CHAUHAN
No comments:
Post a Comment