booths - #include<stdio.h> DEEPAK...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include<stdio.h> DEEPAK AGRAWAL #include<conio.h> SE CMPN A #include<math.h> ROLL NO 03 BOOTHS ALGORITM void main() { int b[8],a[8],q[8],q1,i=-1,j,x,y,r,u,k,carry,s,borrow; clrscr(); printf("ENTER TWO NO\n"); scanf("%d %d",&x,&y); r=x; u=y; if(x<0) x=x*-1; if(y<0) y=y*-1; while(x!=0||y!=0) { i++; b[i]=x%2; x=x/2; q[i]=y%2; y=y/2; } while(i<=3) { i++; b[i]=0; q[i]=0; } if(r<0) { for(j=0;j<=i;j++) { if(b[j]==1) { for(s=j+1;s<=i;s++) { if(b[s]==1) b[s]=0; else b[s]=1; } break; } } } if(u<0) { for(j=0;j<=i;j++) { if(q[j]==1) { for(s=j+1;s<=i;s++) { if(q[s]==1) q[s]=0; else q[s]=1; } break; } } } printf("\nFirst no.is "); for(j=i;j>=0;j--) printf("%d",b[j]); printf("\nSecond no.is "); for(j=i;j>=0;j--) printf("%d",q[j]); for(j=0;j<=i;j++ ) a[j]=0; q1=0; printf("\n\nThe calulation is \n\n"); for(k=0;k<=i;k++) { carry=0; if(q1==0 && q[0]==1) { borrow=0; for(j=0;j<=i;j++) { a[j]=a[j]-b[j]-borrow; if(a[j]==-1) { a[j]=1; borrow=1; } else { if(a[j]==-2) { a [j]=0; borrow=1; } else borrow=0; } } } else { if(q1==1&&q[0]==0) { for(j=0;j<=i;j++) { a[j]=a[j]+b[j]+carry; if(a[j]==2) { a[j]=a[j]%2; carry=1; } else { if(a[j]==3) { a[j]=a[j]%2; carry=1; } else carry=0; } } } } q1=q[0]; for(j=0;j<i;j++) q[j]=q[j+1]; q[i]=a[0]; for(j=0;j<i;j++) a[j]=a[j+1]; printf("\n"); for(j=i;j>=0;j--) printf("%d",a[j]); printf(" "); for(j=i;j>=0;j--) printf("%d",q[j]); printf(" "); printf("%d",q1); } getch(); } /***************OUTPUT************** ENTER TWO NO-5 6 First no.is 11011 Second no.is 00110 The calulation is 00000 00011 0 00010 10001 1 00001 01000 1 11110 00100 0 11111 00010 0 */ #include<stdio.h>#include<stdio....
View Full Document

Page1 / 12

booths - #include<stdio.h> DEEPAK...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online