Friday, April 17, 2009

COMPLEX NUMBERS

#include
void main()
{
int i,a[10],rem,bin=0,base=1,num,j,k,l;
clrscr();
printf(" enter any number\n");
scanf("%d",&num);
i=0;
while(num>0)
{
rem=num%2;
bin=bin+rem*base;
base=base*10;
num=num/2;
a[i]=rem;
i++;
l=j=i;
}

for(i--;i>=0;i--)
printf("%d",a[i]);
for(j--;j>=0;j--)
{
if(a[j]==0a[j]==1)
continue;
else if(a[j]==0)
a[j]=1;
else
a[j]=0;
}
printf("The 2's complement of the given number %d is",num);
for(l--;l>=0;l--)
printf("%d",a[l]);
getch();
}

No comments: