You can do that using PHP shell_exec()
or backticks (``)
PHP supports one execution operator: backticks (``). Note that these are not single-quotes! PHP will attempt to execute the contents of the backticks as a shell command; the output will be returned (i.e., it won't simply be dumped to output; it can be assigned to a variable). Use of the backtick operator is identical to shell_exec().
<?php
$myfile = fopen("newfile.c", "w") or die("Unable to open file!");
$txt = "#include <stdio.h>
int main()
{
printf(\"Hello PHP-C world\");
return 0;
}";
fwrite($myfile, $txt);
fclose($myfile);
$tmp = `gcc -o outputfile newfile.c`;
echo "<pre>$tmp</pre>";
$output = `./outputfile`;
echo "<pre>$output</pre>";
?>
I test it :)

Further reading DOC
N.B : do that gcc shold be installed on your server and you should have permissions
The backtick operator is disabled when safe mode is enabled or shell_exec() is disabled.