Logo 
Search:

C Programming Articles

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

Program to convert binary to decimal

Posted By: Amy Brown     Category: C Programming     Views: 10958

Write a program to convert binary to decimal.

Code for Program to convert binary to decimal 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*2;
    }
    printf("\n BINARY TO DECIMAL CONVERSION IS ");
        printf("%d",sum);
end:
getch();
}
  
Share: 


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

Amy Brown
Amy Brown author of Program to convert binary to decimal is from London, United Kingdom.
 
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!