SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
int a[25],b[25],sum[25],s,c=0,i,n,x,y;
clrscr();
for(x=1;x<=80;x++)
{
for(y=1;y<=50;y++)
{
textbackground(9);
gotoxy(x,y);
cprintf(" ");
}
}
textcolor(2);
gotoxy(35,2);
cprintf("BINARY ADDER");
gotoxy(45,3);
textcolor(44+128);
cprintf("- ");
textcolor(45+128);
cprintf("JEBASTIN J");
{
textcolor(11);
gotoxy(3,6);
cprintf("Enter the number of bit(digit) of the binary number : ");
cin>>n;
if(n==0)
{
JJ:exit(0);
}
else
{
textcolor(13);
cprintf("\n Enter 1st ");
cprintf("%d",n);
cprintf(" bit no.");
textcolor(14);
cprintf("[eg: 1 0 1 1 0] : ");
for(i=0;i<n;i++)
cin>>a[i];
textcolor(13);
cprintf("\n Enter 2nd ");
cprintf("%d",n);
cprintf(" bit no.");
textcolor(14);
cprintf("[eg: 1 0 1 1 0] : ");
for(i=0;i<n;i++)
cin>>b[i];
for(i=n-1;i>=0;i--)
{
if(a[i]==0 && b[i]==0 && c==0)
s=0;
else if(a[i]==0 && b[i]==1 && c==0)
s=1;
else if(a[i]==1 && b[i]==0 && c==0)
s=1;
else if(a[i]==1 && b[i]==1 && c==0)
{
s=0;
c=1;
}
else if(a[i]==0 && b[i]==0 && c==1)
{
s=1;
c=0;
}
else if(a[i]==0 && b[i]==1 && c==1)
s=0;
else if(a[i]==1 && b[i]==0 && c==1)
s=0;
else if(a[i]==1 && b[i]==1 && c==1)
s=1;
else
{
textcolor(3);
gotoxy(25,17);
cprintf("\nWrong bits");
goto JJ;
}
sum[i]=s;
}
textcolor(2);
cprintf("\n\n Addition : ");
if(c==1)
{
textcolor(15);
cprintf("1 ");
}
for(i=0;i<n;i++)
{
textcolor(15);
cprintf("%d ",sum[i]);
}
}
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
int a[25],b[25],sum[25],s,c=0,i,n,x,y;
clrscr();
for(x=1;x<=80;x++)
{
for(y=1;y<=50;y++)
{
textbackground(9);
gotoxy(x,y);
cprintf(" ");
}
}
textcolor(2);
gotoxy(35,2);
cprintf("BINARY ADDER");
gotoxy(45,3);
textcolor(44+128);
cprintf("- ");
textcolor(45+128);
cprintf("JEBASTIN J");
{
textcolor(11);
gotoxy(3,6);
cprintf("Enter the number of bit(digit) of the binary number : ");
cin>>n;
if(n==0)
{
JJ:exit(0);
}
else
{
textcolor(13);
cprintf("\n Enter 1st ");
cprintf("%d",n);
cprintf(" bit no.");
textcolor(14);
cprintf("[eg: 1 0 1 1 0] : ");
for(i=0;i<n;i++)
cin>>a[i];
textcolor(13);
cprintf("\n Enter 2nd ");
cprintf("%d",n);
cprintf(" bit no.");
textcolor(14);
cprintf("[eg: 1 0 1 1 0] : ");
for(i=0;i<n;i++)
cin>>b[i];
for(i=n-1;i>=0;i--)
{
if(a[i]==0 && b[i]==0 && c==0)
s=0;
else if(a[i]==0 && b[i]==1 && c==0)
s=1;
else if(a[i]==1 && b[i]==0 && c==0)
s=1;
else if(a[i]==1 && b[i]==1 && c==0)
{
s=0;
c=1;
}
else if(a[i]==0 && b[i]==0 && c==1)
{
s=1;
c=0;
}
else if(a[i]==0 && b[i]==1 && c==1)
s=0;
else if(a[i]==1 && b[i]==0 && c==1)
s=0;
else if(a[i]==1 && b[i]==1 && c==1)
s=1;
else
{
textcolor(3);
gotoxy(25,17);
cprintf("\nWrong bits");
goto JJ;
}
sum[i]=s;
}
textcolor(2);
cprintf("\n\n Addition : ");
if(c==1)
{
textcolor(15);
cprintf("1 ");
}
for(i=0;i<n;i++)
{
textcolor(15);
cprintf("%d ",sum[i]);
}
}
}
getch();
}
EmoticonEmoticon