C++ program to implement Full Adder
Prerequisite : Full Adder
We are given three inputs of Full Adder A, B,C-IN. The task is to implement the Full Adder circuit and Print output i.e. sum and C-Out of three inputs.
Introduction :
A Full Adder is a combinational circuit that performs an addition operation on three 1-bit binary numbers. The Full Adder has three input states and two output states. The two outputs are Sum and Carry.
Here we have three inputs A, B, Cin and two outputs Sum, Cout. And the truth table for Full Adder is
Logical Expression :
SUM = C-IN XOR ( A XOR B )
C-0UT= A B + B C-IN + A C-IN
Examples –
- Input : A=1, B=0,C-In=0
Output : Sum=1, C-Out=0
Explanation –
Here from logical expression Sum= C-IN XOR (A XOR B ) i.e. 0 XOR (1 XOR 0) =1 , C-Out= A B + B C-IN + A C-IN i.e., 1 AND 0 + 0 AND 0 + 1 AND 0 = 0 .
- Input : A=1, B=1,C-In=0
Output: Sum=0, C-Out=1
Approach :
- Initialize the variables Sum and C_Out for storing outputs.
- First we will take three inputs A ,B and C_In.
- By applying C-IN XOR (A XOR B ) we get the value of Sum.
- By applying A B + B C-IN + A C-IN we get the value of C_Out.
C++
// C++ program to implement full adder #include <bits/stdc++.h> using namespace std; // Function to print sum and C-Out void Full_Adder( int A, int B, int C_In){ int Sum , C_Out; // Calculating value of sum Sum = C_In ^ (A ^ B); //Calculating value of C-Out C_Out = (A & B) | (B & C_In) | (A & C_In); // printing the values cout<< "Sum = " << Sum <<endl; cout<< "C-Out = " << C_Out <<endl; } // Driver code int main() { int A = 1; int B = 0; int C_In = 0; // passing three inputs of fulladder as arguments to get result function Full_Adder(A, B, C_In); return 0; } |
Output
Sum = 1 C-Out = 0
Please Login to comment...