Calculations

C Example to subtract two integer without using minus operator

C Example to subtract two integer without using minus operator

In this article, we will discuss the concept of the C Example to subtract two integer without using minus operator

In this post, we are going to learn how to  write a program to calculate the subtraction of two numbers with out using minus operator in C programming language

subtract two integer without minus

Code to calculate the subtraction of  two numbers 

Subtract two integer without using minus

The program use to calculate subtraction of given two integer numbers without using minus operator in C language

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1=100,num2=20,sub;
    //Variable declaration
    sub=num1+~num2+1;
    //find subtraction without minus
    printf("Subtraction of %d and %d is: %d",num1,num2,sub);
    //display the output
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Subtraction of %d and %d is: %d

 

Subtract two integer without using minus operator – Takes input from user

The program allow the user to enter two value and then calculates subtraction of given two integer numbers  without using minus operator in C language

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1,num2,sub;
    printf("Enter the first number ");
    //ask input from the user
    scanf("%d",&num1);
    //store the input number in num1
      printf("Enter the second number ");
    //ask input from the user
    scanf("%d",&num2);
    //store the input number in num1
    sub=num1+~num2+1;
    //find subtraction without minus
    printf("Subtraction of %d and %d is: %d",num1,num2,sub);
    //display the output
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter the first number 25
Enter the second number 5
Subtraction of 25 and 5 is: 20

 

Methods

  1. Create two variables to store two numbers as input provided by the user: num1,num2;
  2. Create a variable to store the subtraction of these numbers: sub
  3. Request the user to enter first input to store variable num1
  4. Using scanf() function to store the first input value in num1
  5. Request the user to enter second input to store variable num2
  6. Using scanf() function to store the second input value in num2
  7. find the subtraction of num1 and num2 without using minus operator
  8. Finally, display result on the screen- the subtraction of both numbers num1 and num2

 

Suggested for you

Operator in C language

Data type in C language

variable in C language

if statements in C language

Function in C language

 

 

Similar post

Subtract two numbers in C language

Subtract two numbers using function in C language

Subtract two numbers using recursion in C language

Find sum of two numbers in C language

Find sum of two numbers in C language using pointer

Find sum of two numbers in C language using function

Find sum of two numbers in C using recursion

Find sum of two numbers in C without Arithmetic operator

Find sum of natural numbers in C language

Find sum of natural numbers in C language using recursion

 

Python Example to subtract two integer without using minus operator
C++ Example to subtract two integer without using minus operator
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

20 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago