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
Subtract Two Numbers Without Minus Operator in C
✅ C Program to Subtract Two Numbers Without Using Minus Operator
#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers (a - b):\n");
scanf("%d %d", &a, &b);
while (b != 0) {
int borrow = (~a) & b; // borrow calculation
a = a ^ b; // subtraction using XOR
b = borrow << 1; // shift borrow to left
}
printf("Difference is: %d\n", a);
return 0;
}
๐ Explanation:
This program performs subtraction without using the minus (-) operator. Instead, it uses bitwise operators:
borrow = (~a) & b→ Finds the borrow bits.a = a ^ b→ Performs subtraction without borrow.b = borrow << 1→ Shifts borrow to the correct place.- The loop continues until no borrow is left.
๐งพ Sample Output:
Enter two numbers (a - b): 15 7 Difference is: 8
๐ Keywords:
C program subtraction without minus, bitwise subtraction in C, subtraction without arithmetic operator, coding interview bitwise questions
๐ Hashtags:
#CProgramming #BitwiseOperators #Subtraction #InterviewPrep #LearnC
๐ Search Description:
Learn how to subtract two numbers in C without using minus operator. Uses XOR, AND, NOT, and shift operations. Explained with code and output.
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