Recent Posts

9-latest-250px-course

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



Program:-     

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

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

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

i = 1;

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

return octal;
}

int main()
{
long int binary;

printf(“\nEnter a binary number: “);
scanf(“%lld”, &binary);

printf(“\nOctal Equivalent : %d\n”, binary_to_octal(binary));

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