mkdir
cd
pwd
ls
cp
mv
rm
rmdir
man
man diff
passwd
Which of the following are valid variable names in C? Which are not?
THX1138
: valid
2for1
: invalid (begins with a digit)
MrBean
: valid
My Space
: invalid (contains a space)
still_counting
: valid
^oo^
: invalid (contains punctuation)
_MEMLIMIT
: valid, but discouraged (begins with underscore)
#include <stdio.h> #include <math.h> int main( void ) { float x; printf("Enter a number: " ); scanf( "%f", &x ); printf("The square root of %1.2f is %1.2f\n", x, sqrt(x)); return 0; }
pow()
function, described
here).
replacesqrt(x)
withpow( x, 1.0/3.0)
heron.c
.
What would you type on the UNIX command line to compile this program,
producing the object file heron
?
How would you then run this program?
gcc -Wall -o heron heron.c
a, b
and c
of a triangle, and computes the area of the triangle
using Heron's formula:
area = sqrt(s(s-a)(s-b)(s-c))where
s
is the "semi-perimeter"
s = (a + b + c)/2.
/* heron.c Use Heron's formula to compute the area of a triangle, given the side lengths. */ #include <stdio.h> #include <math.h> // remember to compile with -lm int main( void ) { float a,b,c; // sidelengths of a triangle float s; // semi-perimeter float area; printf( "Enter sidelengths of a triangle:\n" ); scanf( "%f", &a ); scanf( "%f", &b ); scanf( "%f", &c ); // compute semi-perimeter s = ( a + b + c )/ 2; // compute area using Heron's formula area = sqrt(s*(s-a)*(s-b)*(s-c)); printf( "Area = %1.2f\n", area ); return 0; }