Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

Subtract Two Numbers Without Minus Operator in C

C Program to Subtract Two Numbers Without Using Minus Operator

✅ 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.

Comments

Popular Posts

πŸŒ™