I am trying to compile code using gcc and run the executable, but it is throwing error:
gcc somefile.c -o somefile
compilation goes through su
your somefile is executable binary, it's not shell script. you should execute it by:
somefile
$./somefile