Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to convert binary to octal

Posted By: Adalfreddo Fischer     Category: C Programming     Views: 12775

Write a program to convert binary to octal.

Code for Program to convert binary to octal in C Programming

#include<stdio.h>
#include<conio.h>
void main()
{
    int j=1,i=0;
    int k,num[100],n,sum=0;
    clrscr();
    printf("\n PLEASE ENTER VALUE N:");
    scanf("%d",&n);
    printf("\n PLEASE ENTER IN THE BINARY (0 - 1): ");
    for(k=0;k<n;k++)
    {
    printf("\n\tnum[%d]= ",k+1);
    scanf("%d",&num[k]);
    if(num[k]>1)
    {
        printf("\n YOU ARE NOT ENTER BINARY NUMBER");
        goto end;
    }
    }
    for(k=n-1;k>=0;k--)
    {
        sum=sum+(num[k]*j);
        j=j*8;
    }
    printf("\n BINRY TO OCTAL CONVERSION IS ");
        printf("%d",sum);
end:
getch();
}
  
Share: 


Didn't find what you were looking for? Find more on Program to convert binary to octal Or get search suggestion and latest updates.

Adalfreddo Fischer
Adalfreddo Fischer author of Program to convert binary to octal is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!