#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],m[10],q[10],i,j,c=0,b[10],mc[10],z=0,s[10],x[10];
clrscr();
printf("\nEnter Divisor [M] : ");
for(i=4;i>=1;i--)
{
scanf("%d",&m[i]);
mc[i]=!m[i];
a[i]=0, x[i]=0;
}
x[1]=1, x[5]=0, m[5]=0, mc[5]=1;
for(i=1;i<=5;i++)
{
s[i]=x[i]^mc[i]^z;
c=(x[i]&&mc[i])||(x[i]&&z)||(mc[i]&&z);
z=c;
mc[i]=s[i];
}
printf("\n\nEnter Divident [Q] : ");
for(i=4;i>=1;i--)
{
scanf("%d",&q[i]);
}
printf("\n\n\n Step \t\t Action Performed \t\t A \t\tQ\n");
printf("\n\n 0\t\t Initialization\t 0 0 0 0 0 \t ");
for(i=4;i>=1;i--)
{
printf(" %d",q[i]);
}
for(j=1;j<=4;j++)
{
printf("\n\n\n %d",j);
printf("\t\t Left Shift \t\t ");
for(i=5;i>=2;i--)
{
a[i]=a[i-1];
}
a[1]=q[4];
for(i=4;i>=2;i--)
{
q[i]=q[i-1];
}
for(i=5;i>=1;i--)
{
printf(" %d",a[i]);
}
printf("\t ");
for(i=4;i>=2;i--)
{
printf(" %d",q[i]);
}
if(a[5]==0)
{
z=0;
for(i=1;i<=5;i++)
{
s[i]=a[i]^mc[i]^z;
c=(a[i]&&mc[i])||(a[i]&&z)||(mc[i]&&z);
z=c;
a[i]=s[i];
}
if(a[5]==1)
{
q[1]=0;
}
else
{
q[1]=1;
}
printf("\n\n\t\t a = a-m\t\t ");
for(i=5;i>=1;i--)
{
printf(" %d",a[i]);
}
printf("\t ");
for(i=4;i>=1;i--)
{
printf(" %d",q[i]);
}
}
else
{
z=0;
for(i=1;i<=5;i++)
{
s[i]=a[i]^m[i]^z;
c=(a[i]&&m[i])||(a[i]&&z)||(m[i]&&z);
z=c;
a[i]=s[i];
}
if(a[5]==1)
{
q[1]=0;
}
else
{
q[1]=1;
}
printf("\n\n\t\t a = a+m\t\t ");
for(i=5;i>=1;i--)
{
printf(" %d",a[i]);
}
printf("\t ");
for(i=4;i>=1;i--)
{
printf(" %d",q[i]);
}
}
}
if(a[5]==1)
{
printf("\n\n\n 5");
for(i=1;i<=5;i++)
{
s[i]=a[i]^m[i]^z;
c=(a[i]&&m[i])||(a[i]&&z)||(m[i]&&z);
z=c;
a[i]=s[i];
}
printf("\t\t a = a+m\t\t ");
for(i=5;i>=1;i--)
{
printf(" %d",a[i]);
}
printf("\t ");
for(i=4;i>=1;i--)
{
printf(" %d",q[i]);
}
}
printf("\n\n\n\n\nQuotient [Q] :");
for(i=4;i>=1;i--)
{
printf(" %d",q[i]);
}
printf("\n\n\n\nRemainder [A] :");
for(i=4;i>=1;i--)
{
printf(" %d",a[i]);
}
getch();
}
/* OUTPUT */
Enter Divisor [M] : 0 0 1 1
Enter Divident [Q] : 1 0 0 0
Step Action Performed A Q
0 Initialization 0 0 0 0 0 1 0 0 0
1 Left Shift 0 0 0 0 1 0 0 0
a = a-m 1 1 1 1 0 0 0 0 0
2 Left Shift 1 1 1 0 0 0 0 0
a = a+m 1 1 1 1 1 0 0 0 0
3 Left Shift 1 1 1 1 0 0 0 0
a = a+m 0 0 0 0 1 0 0 0 1
4 Left Shift 0 0 0 1 0 0 0 1
a = a-m 1 1 1 1 1 0 0 1 0
5 a = a+m 0 0 0 1 0 0 0 1 0
Quotient [Q] : 0 0 1 0
Remainder [A] : 0 0 1 0
Thanks a lot bro,stay blessed
ReplyDeleteits showing an error
ReplyDeletenot warking showing same output
ReplyDelete