SOURCE CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
long int i,a,b,n=1,sum=0;
clrscr();
printf("Enter binary no.");
scanf("%ld",&i);
while(i>0)
{
a=i%10;
b=a*n;
sum=sum+b;
i=i/10;
n=n*2;
}
printf("\ndecimal is %ld",sum);
sum=0;
n=1;
printf("\n\nEnter decimal no.");
scanf("%ld",&i);
while(i>0)
{
b=i%2;
i=i/2;
sum=sum+b*n;
n=n*10;
}
printf("\nbinary is %ld",sum);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
long int i,a,b,n=1,sum=0;
clrscr();
printf("Enter binary no.");
scanf("%ld",&i);
while(i>0)
{
a=i%10;
b=a*n;
sum=sum+b;
i=i/10;
n=n*2;
}
printf("\ndecimal is %ld",sum);
sum=0;
n=1;
printf("\n\nEnter decimal no.");
scanf("%ld",&i);
while(i>0)
{
b=i%2;
i=i/2;
sum=sum+b*n;
n=n*10;
}
printf("\nbinary is %ld",sum);
getch();
}
No comments :
Post a Comment