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