Wednesday, 20 November 2013

2's complement

#include<stdio.h>

2's complement cprogram


#include<string.h>
void main()
{
char b[20];
int i,j,l;
clrscr();
printf("Enter a binary num");
scanf("%s",b);
l=strlen(b);
for(i=l-1;i>=0;i--)
{
if(b[i]=='1')
{
for(j=i-1;j>=0;j--)
{
if(b[j]=='1')
b[j]='0';
else
b[j]='1';
}
}
}
printf("2's compliment is %s",b);
getch();
}

No comments:

Post a Comment