#include<stdio.h>
void main()
{
long int i,n,mul,mul2,count,temp,a,b,sum,carry,res,tot;
clrscr();
printf("\nEnter any 2 numbers : ");
scanf("%ld %ld",&mul,&n);
mul2=temp=mul;
for (i=2; i<=n; i++)
{
temp=mul;
count=32;
res=1;
tot=sum=carry=0;
while (count--)
{
a=temp & 0x1;
b=mul2 & 0x1;
if ((a^b==1) && (carry==1))
{
sum=(a^b)^carry;
carry=(a^b)&carry;
}
else
{
sum=a^b|carry;
carry=a&b;
}
temp=temp>>1;
mul2=mul2>>1;
tot+=res*sum;
res=res*2;
}
mul2=tot;
}
printf("\n%3ld * %3ld = %3ld",mul,i-1,tot);
getch();
}
No comments:
Post a Comment