Skip to main content

Binary to Decimal Conversion Program in C Programming

1 min read
Share:
On this page (4sections)

About this program

This is an example program in c other programs. Read the concept first: If Else Statement in C, then study the code and output below.

Example Program For Binary to Decimal Conversion

/* Example Program For Binary to Decimal In C Programming Language

little drops @ thiyagaraaj.com



Coded By:THIYAGARAAJ MP             \*/

// Header Files

#include<stdio.h>

#include<conio.h>

int to_decimal(int);

//Main Function

int main()

{

//Varibale Declaration

int n;



printf("Enter the Binary Number:");

scanf("%d",&n);



printf("Decimal Numebr : %d",to\_decimal(n));



// Wait For Output Screen

getch();



//Main Function return Statement

return 0;

}

// Function for Binary to Decimal

int to_decimal(int num)

{

int sum=0,i=0;

while(num!=0)

{

sum=sum+(num%10)\*pow(2,i++);

num/=10;

}

return sum;

}

Sample Output:

Enter the Binary Number:1010

Decimal Numebr : 10

Enter the Binary Number:1000

Decimal Numebr : 8

Learn the concept first, then study the code:

Related Tutorials

Search tutorials