C Program Addition and Subtraction without using + - Operators

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
We can do addition and subtraction without using +,- operators in C Language.
#include<stdio.h>
 int addition(int x, int y) {
   int a, b;
   do {
     a = x & y;
     b = x ^ y;
     x = a << 1;
     y = b;
   } while (a);
   return b;
 }
 int main(void) {
   printf("10+20 = %d", addition(10, 20));
   return 0;
 }
Output:
10+20 = 30
#include<stdio.h> 

int sub(int x, int y) {
  unsigned a, b;
  do {
    a = ~x & y;
    b = x ^ y;
    x = b;
    y = a << 1;
  } while (a);
  return b;
}
int main(void) {
  printf("10 - 20 = %d", sub(10, 20));
  return 0;
}
Output:
10 - 20 = -10
Happy Learning 🙂

C Program – Addition of two Matrices Example
Java Program For Binary Addition
C Program – Bubble Sort Program in C
C Program – Given number is Even or Odd
C Program – Reverse of a number
C Program – Find GCD of two numbers
C Program to add elements of an array
C Program – Multiplication of two Matrices Example
PHP Operators Example Tutorials
Python Operators Example
C Program – Ways to Generate Fibonacci Series
C Program – Print the sum of digits of given number
C Program – Sum of digits of given number till single digit
C Program – Check a number is Palindrome or not
C Program – Find the factorial of given number

C Program – Addition of two Matrices Example
Java Program For Binary Addition
C Program – Bubble Sort Program in C
C Program – Given number is Even or Odd
C Program – Reverse of a number
C Program – Find GCD of two numbers
C Program to add elements of an array
C Program – Multiplication of two Matrices Example
PHP Operators Example Tutorials
Python Operators Example
C Program – Ways to Generate Fibonacci Series
C Program – Print the sum of digits of given number
C Program – Sum of digits of given number till single digit
C Program – Check a number is Palindrome or not
C Program – Find the factorial of given number
 


Δ
 C – Introduction
 C – Features
 C – Variables & Keywords
 C – Program Structure
 C – Comment Lines  & Tokens
 C – Number System
 C – Local and Global Variables
 C – Scope & Lifetime of Variables
 C – Data Types
 C – Integer Data Types
 C – Floating Data Types
 C – Derived, Defined Data Types
 C – Type Conversions
 C – Arithmetic Operators
 C – Bitwise Operators
 C – Logical Operators
 C –  Comma and sizeof Operators
 C – Operator Precedence and Associativity
 C – Relational Operators
 C Flow Control – if, if-else, nested if-else, if-else-if
 C – Switch Case
 C Iterative – for, while, dowhile loops
 C Unconditional – break, continue, goto statements
 C – Expressions and Statements
 C – Header Files & Preprocessor Directives
 C – One Dimensional Arrays
 C – Multi Dimensional Arrays
 C – Pointers Basics
 C – Pointers with Arrays
 C – Functions
 C – How to Pass Arrays to Functions
 C – Categories of Functions
 C – User defined Functions
 C – Formal and Actual Arguments
 C – Recursion functions
 C – Structures Part -1
 C – Structures Part -2
 C – Unions
 C – File Handling
 C – File Operations
 C – Dynamic Memory Allocation
 C Program – Fibonacci Series
 C Program – Prime or Not
 C Program – Factorial of Number
 C Program – Even or Odd
 C Program – Sum of digits till Single Digit
 C Program – Sum of digits
 C Program – Reverse of a number
 C Program – Armstrong Numbers
 C Program – Print prime Numbers
 C Program – GCD of two Numbers
 C Program – Number Palindrome or Not
 C Program – Find Largest and Smallest number in an Array
 C Program – Add elements of an Array
 C Program – Addition of Matrices
 C Program – Multiplication of Matrices
 C Program – Reverse of an Array
 C Program – Bubble Sort
 C Program – Add and Sub without using + –