Recent Posts

9-latest-250px-course

Write a C program to Convert a number from octal to binary

Write a C program to Convert a number from octal to binary



Program:-     

#include <stdio.h>
#include <math.h>

long long octal_to_binary(int octal)
{
int decimal = 0, i = 0;
long long binary = 0;

while(octal != 0)
{
decimal += (octal%10) * pow(8,i);
++i;
octal/=10;
}

i = 1;

while (decimal != 0)
{
binary += (decimal % 2) * i;
decimal /= 2;
i *= 10;
}

return binary;
}


int main()
{
int octal;

printf(“\nEnter an octal number: “);
scanf(“%d”, &octal);

printf(“\nBinary Equivalent : %d\n”, octal_to_binary(octal));

return 0;
}

Output:-

....
SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment