Skip to main content

Featured

functions in Python

C++ program to convert binary to decimal


C++ program to convert binary to decimal



//program to convert a binary no. into decimal no.

#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

{clrscr();

long int n,x;

cout<<"Please enter a binary no. "<<endl;

cin>>n;

x=n;

int rem=0,sum=0;

for(int ctr=0;n>0;ctr++)

{ rem=n%10;

  rem=rem*(pow(2,ctr));

  sum=sum+rem;

  n=n/10;

}

cout<<"Decimal Equivalent of "<<x<<" is "<<sum<<endl;

getch();

}//end main


Comments

Popular Posts