e3 - #include<stdio.h> #include<conio.h>...

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

View Full Document Right Arrow Icon
#include<stdio.h> #include<conio.h> #include<math.h> /* RISHI AGARWAL   MULTIPLY:BOOTHS ALGO    ROLL NO 02 SE CMPN A*/ int mx=0; struct stack {  int data[10];  int top; }; int mul[20]; struct stack add(struct stack *p,struct stack *q,int *c) {  struct stack z;  int i,max,t1,t2;  z.top=-1;  if(p->top>q->top)  max=p->top;  else  max=q->top;  for(i=0;i<=max;i++)  {   if(i<=p->top)   t1=p->data[i];   else   t1=0;   if(i<=q->top)   t2=q->data[i];   else   t2=0;   z.data[i]=(t1+t2+(*c))%2;   (z.top)++;   if(t1+t2+(*c)<2)   (*c)=0;   else   (*c)=1;  }  return z; } void dectobin(int z,struct stack *p) {int x,t=0,f=1;  x=z;  p->top=-1; if(mx==0) {do  {   (p->top)++;   p->data[p->top]=x%2;   x=x/2;   t++;   if(x==0)    f--;
Background image of page 1

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

View Full DocumentRight Arrow Icon
 }while(x>0||f==0); } else {t=mx;  do  {(p->top)++;   p->data[p->top]=x%2;   x=x/2;   t--;  }while(t>0); }  if(t>mx)   mx=t;} void display(struct stack *p) {  int z;  z=p->top;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

e3 - #include&lt;stdio.h&gt; #include&lt;conio.h&gt;...

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

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