Convert binary to decimal using One Dimensional Array in C


This program is about convert and print the given binary number to decimal value using for loops and power functions.

Source Code

#include<stdio.h>
int main()
{
  int i,bin=0,n,a[10];
  printf("\nEnter the Binary number:");
  scanf("%d",&n);
  for(i=0;n!=0;i++)
  {
    a[i]=n%10;
    n=n/10;
  }
  n=i;
  for(i=0;i<n;i++)
  {
    bin+=a[i]*pow(2,i);
  }
  printf("%d",bin);
  return 0;
}
To download raw file Click Here

Output

Enter the Binary number:1100
Decimal Value: 12

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes