Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! π πΉLearn advanced coding techniques in C& C++ πΉMaster Linux internals & shell scripting πΉDeep dive into Data Structures & Algorithms πΉExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) πΉGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C Program to Add Two Numbers Without '+' Operator
✅ C Program to Add Two Numbers Without '+' Operator
#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers:\n");
scanf("%d %d", &a, &b);
while (b != 0) {
int carry = a & b; // Calculate carry
a = a ^ b; // Add without carrying
b = carry << 1; // Shift carry to the left
}
printf("Sum is: %d\n", a);
return 0;
}
π Explanation:
This program adds two numbers without using the + operator.
It uses bitwise operations:
a ^ bcalculates the sum without carrya & bfinds the carrycarry << 1shifts the carry to the next bit- The loop continues until there’s no carry
π₯️ Sample Output:
Enter two numbers: 5 3 Sum is: 8
π Keywords:
add without plus, bitwise sum, binary addition, C program without + operator, xor carry logic, beginner bitwise program
π Hashtags:
#CProgramming #BitwiseOperations #BinaryAddition #NoPlusOperator #XORLogic #BeginnerC
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment