You are on page 1of 2

Bharatiya Vidya Bhavan’s

Sardar Patel Institute of Technology


Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India
(Autonomous College Affiliated to University of Mumbai)
SE-ETRX Sub- CAO lab

NAME : Shubham Sawant


UID NO : 2019110050
EXPERIMENT 6
NO. :
SOFTWARE : C

Program
AIM : Design of Carry Look Ahead Adder

PROGRAM : #include<stdio.h>
int
main ()
{
int X[4], Y[4];
int C[4],P[4],G[4],S[4];
C[0] = 0;
int BinX, BinY;
printf ("Enter the value of 1st number : ");
scanf ("%d", &BinX);
printf ("Enter the value of 2nd number : ");
scanf ("%d", &BinY);
int BinX1, BinY1, i;
BinX1 = BinX;
BinY1 = BinY;
for (i = 0; i < 4; i++)
{
X[i] = BinX1 % 2;
BinX1 = BinX1 / 2;
Y[i] = BinY1 % 2;
BinY1 = BinY1 / 2;
}
printf ("Binary of 1st number(%d): ", BinX);
for (i = 3; i >= 0; i--)
{
printf ("%d", X[i]);
}
printf ("\nBinary of 2nd number(%d): ", BinY);
for (i = 3; i >= 0; i--)
{
printf ("%d", Y[i]);
}
for (i = 0; i < 4; i++)
{
if ((X[i] == Y[i]))
P[i] = 0;
Bharatiya Vidya Bhavan’s
Sardar Patel Institute of Technology
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India
(Autonomous College Affiliated to University of Mumbai)
SE-ETRX Sub- CAO lab

else
P[i] = 1;
if ((X[i] == 1 && Y[i] == 1))
G[i] = 1;
else
G[i] = 0;
if ((P[i]==0 || C[i]==0) && G[i]==0)
C[i + 1] = 0;
else
C[i + 1] = 1;
}
for (i = 0; i < 4; i++)
{
if (P[i] == C[i])
S[i] = 0;
else
S[i] = 1;
}
printf ("\nSum = ");
for (i = 3; i >= 0; i--)
{
printf ("%d", S[i]);
}
printf ("\nCarry= %d\n", C[4]);
return 0;
}
Output : Output1:

Output2:

Conclusion : From this Experiment, we learnt how to Carry Look Ahead Adder .

You might also like