Banner Header

Monday, 28 August 2017

C Program Subtraction of two Numbers

C Program to Sub Two Numbers

In this program, user is asked to enter two integers. Then, the sub of those two integers is stored in a variable and displayed on the screen.

sub of two numbers


Program to Sub Two Integers

#include <stdio.h>
#include <conio.h>
int main()
{
    int firstNumber, secondNumber, subOfTwoNumbers;
   
    printf("Enter two integers: ");

    // Two integers entered by user is stored using scanf() function
    scanf("%d %d", &firstNumber, &secondNumber);

    // sub of two numbers in stored in variable sumOfTwoNumbers
    subOfTwoNumbers = firstNumber - secondNumber;

    // Displays sub     
    printf("%d - %d = %d", firstNumber, secondNumber, subOfTwoNumbers);

getch();
}


Output
Enter two integers: 12
11
12 - 11 = 1

In this program, user is asked to enter two integers. Two integers entered by the user is stored in variables firstNumber and secondNumber respectively. This is done using scanf()function.
Then, variables firstNumber and secondNumber are subtracting using - operator and the result is stored in subOfTwoNumbers.

Finally, the subofTwoNumbers is displayed on the screen using printf() function.

Click on the download button to download file

 Download Button



C Program Subtraction of two Numbers Reviewed by Waqas Ahmed Mir PC on August 28, 2017 Rating: 5 C Program to Sub Two Numbers In this program, user is asked to enter two integers. Then, the sub of those two integers is stored in a variab...

No comments: