ASALAM WALAKUM,
Well this is a Program to convert a Binary Number input by the user to a Decimal Number. It is a very simple one without an array , which I personally think adds to the efficiency of my Programming skills :D.
Regards,
Nabeel
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int num=0,sum=0,digit=0,temp=0,a=0;
printf("ENTER A BINARY NUMBER :\t");
scanf("%d",&num);
int result=num;
while(num!=0)
{
digit=num%10;
temp=digit*pow(2,a);
sum+=temp;
num=num/10;
a++;
}
printf("THE DECIMAL EQUIVALENT OF %d IS %d ",result,sum);
getch();
}
No comments:
Post a Comment