0% found this document useful (0 votes)
4 views

Subtraction

Uploaded by

amoghmemories2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Subtraction

Uploaded by

amoghmemories2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Below is a simple C program to subtract two numbers with an explanation:

C Code:

#include <stdio.h>

int main() {

// Declare variables to store two numbers and the result

int num1, num2, result;

// Prompt the user to enter the first number

printf("Enter the first number: ");

scanf("%d", &num1);

// Prompt the user to enter the second number

printf("Enter the second number: ");

scanf("%d", &num2);

// Perform subtraction

result = num1 - num2;

// Display the result

printf("The result of subtraction is: %d\n", result);

return 0; // Indicate that the program ended successfully

Explanation:

1. Include the Header File (#include <stdio.h>):

o The stdio.h library is included to enable input/output functions like printf and scanf.

2. Declare Variables:

o Three integer variables (num1, num2, result) are declared to store the input
numbers and the result of the subtraction.
3. Input Numbers:

o The program prompts the user to enter two integers using printf, and scanf reads the
inputs.

4. Perform Subtraction:

o The subtraction operation num1 - num2 is performed and stored in the result
variable.

5. Display the Result:

o The program prints the result using printf.

6. Return Statement:

o The return 0; at the end of the main() function signifies that the program executed
successfully.

Example Output:

Input:

Enter the first number: 15

Enter the second number: 7

Output:

The result of subtraction is: 8

You might also like