The classic first input exercise: read two numbers and add them.
What to build
A program that adds two numbers.
Requirements
- Read two integers from one line.
- Print their sum.
Input
One line: two integers.
Output
One integer.
Constraints
-1000000 ≤ a, b ≤ 1000000.
Example
Input:
3 4
Output:
7
Why it works
fscanf with %d reads whole numbers, so the addition is a real number sum and not text joining.
Examples
Example 1 · Input
3 4
Expected output
7
Example 2 · Input
-5 5
Expected output
0
Hints
Hint 1
fscanf(STDIN, "%d %d", $a, $b) reads two integers from one line.
Hint 2
Print $a + $b.
Solution
Show one correct solution (try it yourself first)
<?php fscanf(STDIN, "%d %d", $a, $b); echo $a + $b, "\n";