Compose Two Functions
PHP
Hard
3 views
Problem Description
Input x. Define f(x)=x+3 and g(x)=x*2. Compute g(f(x)) and f(g(x)) and print both.
Input Format
One integer x.
Output Format
Two integers: g(f(x)) f(g(x)).
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$x=intval($inputText);
function f2($x){ return $x+3; }
function g2($x){ return $x*2; }
$one=g2(f2($x));
$two=f2(g2($x));
echo $one.' '.$two;
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!