×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Difference between Structure and Class - MAKAUT / WBUT MCA Slove
convert a binary numbers to equivalent decimal number in C Language - MAKAUT / WBUT MCA 2011 - C Language
1427    Arnab De    14/11/2019

Write a c program to convert a binary numbers to equivalent decimal number. [WBUT MCA 2011]

softetechnologies
#include <stdio.h>
#include <math.h>

int main()
{
	char nos[20];
	int i,fl=1,res=0,temp;
	printf("Enter A Numbers : ");
	gets(nos);
	//check for valid binary number
	for(i=0;nos[i]!='\0';i++)
	{
		//48 and 49 is the ascii code for 0 and 1 respectively
		if(nos[i] < 48 || nos[i] >  49)
		{
			fl=0;
			break;
		}
 	}
	if(fl)
	{
		strrev(nos);
		puts(nos);
		for(i=0;nos[i]!='\0';i++)
		{
			temp=nos[i]-48;
			res += temp * pow(2,i);
		}
		printf("Binary eqivalent of %s is %d",nos,res);
	}
	else
	{
		printf("!!! *** INVALID BINARY NUMBER *** !!!");
	}
}
softetechnologies

Output

======

Enter A Numbers : 1011

Binary eqivalent of 1101 is 11

Difference between Structure and Class - MAKAUT / WBUT MCA Slove
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
All that man has to do is to take care of three things; good thought, good word, good deed.
Swami Vivekananda
1889
66.09
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     48309
25/06/2018     40334
01/01/2018     39790
28/06/2017     37666
02/08/2017     36402
01/08/2017     30652
06/07/2017     30398
15/05/2017     29850
14/07/2017     25833
11/09/2018     25308
softetechnologies