Pages

Ads 468x60px

Saturday, 2 June 2012

C Program For BINARY TO DECIMAL


C Program For BINARY TO DECIMAL



This program prompts the user for a positive integer. The function binary divides
 the integer by 2 (using the bitshift operation) until the number becomes 1, at which
 point it outputs 1 and steps back thru the function calls outputting the remainder
 from previous divisions. This program has been tested and works for all integers 
within C++ limits.

CODE:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int s=0,z=0,n,t;
clrscr();
printf("Enter the n value");
scanf("%d",&n);
while(n>0)
{
t=n%10;
s=s+(t*pow(2,z++));
printf("s=%d\n",s);
n=n/10;
}
printf("given number is=%d",s);
getch();
}

0 comments:

Post a Comment

Total Pageviews