C program to convert Binary to Octal.

#include<stdio.h>
#include<conio.h>
int main()
{
    int bin, oct=0, i=0, mul=1, count=1, rem, octnum[20];
    printf("Enter any Binary Number: ");
    scanf("%d", &bin);
    while(bin!=0)
    {
        rem = bin%10;
        oct = oct + (rem*mul);
        if(count%3==0)
        {
            octnum[i] = oct;
            mul = 1;
            oct = 0;
            count = 1;
            i++;
        }
        else
        {
            mul = mul*2;
            count++;
        }
        bin = bin/10;
    }
    if(count!=1)
        octnum[i] = oct;
    printf("\n Octal Value = ");
    for(i=i; i>=0; i--)
        printf("%d", octnum[i]);
    getch();
    return 0;
}
C program to convert Binary to Octal. C program to convert Binary to Octal. Reviewed by on December 22, 2019 Rating: 5

No comments:

Powered by Blogger.