gpt-4o-2024-08-06· openai
from WildChat-4.8M
code for subtraction of two
- User
code for subtraction of two
- Assistant
To perform a subtraction of two numbers in various programming languages, you can use simple expressions. Below are examples in a few popular languages:
Python
python# Define two numbers a = 10 b = 5 # Subtract b from a result = a - b # Print the result print("Subtraction result:", result)JavaScript
javascript// Define two numbers let a = 10; let b = 5; // Subtract b from a let result = a - b; // Print the result console.log("Subtraction result:", result);Java
javapublic class SubtractionExample { public static void main(String[] args) { // Define two numbers int a = 10; int b = 5; // Subtract b from a int result = a - b; // Print the result System.out.println("Subtraction result: " + result); } }C++
cpp#include <iostream> int main() { // Define two numbers int a = 10; int b = 5; // Subtract b from a int result = a - b; // Print the result std::cout << "Subtraction result: " << result << std::endl; return 0; }C
c#include <stdio.h> int main() { // Define two numbers int a = 10; int b = 5; // Subtract b from a int result = a - b; // Print the result printf("Subtraction result: %d\n", result); return 0; }Each of these snippets shows you how to subtract two numbers and print the result. You can replace the values
10and5with any numbers you want to subtract.