Description
In this program, program will take two number as input and give subtraction of the two number as output. The first input stored in variable firstNumber and second input stored in variable secondNumber. The variables firstNumber and secondNumber are subtracted using the arithmetic operator - and the result is stored in the variable sub. example : firstNumber = 15 secondNumber = 10 sub = 5
C/C++
/* C Program to subtract two numbers */ //Save it as SubtractTwoNumbers.c #include<stdio.h> int main(){ int firstNumber, secondNumber, sub; printf("Enter the first number : "); scanf("%d",&firstNumber); printf("Enter the second number : "); scanf("%d",&secondNumber); sub = firstNumber - secondNumber; printf("The subtraction of %d and %d is %d",firstNumber,secondNumber,sub); return 0; }
Input: Enter the first number : 12 Enter the second number : 3 Output: The subtraction of 12 and 3 is 9
Java
/* Java Program to subtract two numbers */ //Save it as SubtractTwoNumbers.java import java.io.*; import java.util.Scanner; public class SubtractTwoNumbers { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int firstNumber, secondNumber, sub; System.out.println("Enter the first number : "); firstNumber = scanner.nextInt(); System.out.println("Enter the second number : "); secondNumber = scanner.nextInt(); sub = firstNumber - secondNumber; System.out.println("The subtraction of "+firstNumber+" and "+secondNumber+" is "+ sub); } }
Input: Enter the first number : 15 Enter the second number : 2 Output: The subtraction of 15 and 2 is 13
Related Programs
1) Add Two Numbers2) Program to multiply two numbers
3) Program to divide two numbers
4) Program to find modulus of two numbers
5) Program to find Quotient and Remainder
6) Program to calculate power of a number
7) Program to calculate Permutation And Combination
8) Program to find simple interest
9) Program to calculate Gross Salary
10) Program to calculate percentage mark of student