Pogram to Add Two Numbers
- Write a program to add two numbers in C
- Write a program to add two numbers in C++
- Write a program to add two numbers in Python
- Write a program to add two numbers in PHP
- Write a program to add two numbers in Java
- Write a program to add two numbers in Java Script
- Write a program to add two numbers in C#
Explanation:
In programming, adding two numbers is a basic operation. Using the addition operator (+), two input values (numbers) are added, and the result is either displayed or returned. Here is a detailed explanation of the reasoning:
Steps:
- Input the Numbers:
- Read two numbers from the user or use predefined values.
- Perform the Addition:
- Use the addition operator (+) to calculate the sum of the two numbers.
- Output the Result:
- Display or return the calculated sum.
Pogram to Add Two Numbers
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> int main() { int a, b, sum; printf("Enter two numbers: "); scanf("%d %d", &a, &b); sum = a + b; printf("The sum is: %d\n", sum); return 0; }
#include <iostream> int main() { int a, b; std::cout << "Enter two numbers: "; std::cin >> a >> b; std::cout << "The sum is: " << a + b << std::endl; return 0; }
a = int(input("Enter the first number: ")) b = int(input("Enter the second number: ")) print("The sum is:", a + b)
<?php $a = readline("Enter the first number: "); $b = readline("Enter the second number: "); echo "The sum is: " . ($a + $b) . "\n"; ?>
import java.util.Scanner; public class AddNumbers { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter two numbers: "); int a = scanner.nextInt(); int b = scanner.nextInt(); System.out.println("The sum is: " + (a + b)); } }
const a = parseInt(prompt("Enter the first number: ")); const b = parseInt(prompt("Enter the second number: ")); console.log("The sum is:", a + b);
using System; class AddNumbers { static void Main() { Console.Write("Enter the first number: "); int a = int.Parse(Console.ReadLine()); Console.Write("Enter the second number: "); int b = int.Parse(Console.ReadLine()); Console.WriteLine("The sum is: " + (a + b)); } }