Friday, July 13, 2012

Simple C Program


#include  <stdio.h>
int main ()
{
     printf ( “Hello, World!\n” ) ;
     return 0 ;
}



Program Header Comment and Preprocessor Directives

A comment is descriptive text used to help a reader of the program understand its content.
All comments must begin with the characters  /*  and end with the characters  */
These are called comment delimiters
The program header comment always comes first.

Lines that begin with a # in column 1 are called preprocessor directives (commands).
Example:  the #include <stdio.h> directive causes the preprocessor to include a copy of the standard input/output header file stdio.h at this point in the code.
This header file was included because it contains information about the printf ( ) function that is used in this 
program.

C Standard Library


Every implementation of C comes with a standard library of predefined functions.
Note that, in programming, a library is a collection of functions.
The functions that are common to all versions of C are known as the C Standard Library.




Function
Name
Math
Name
Value
Example
abs(x)
absolute value
|x|
abs(-1)
returns
1
sqrt(x)
square root
x0.5
sqrt(2.0)
returns
1.414…
exp(x)
exponential
ex
exp(1.0)
returns
2.718…
log(x)
natural logarithm
ln x
log(2.718…)
returns
1.0
log10(x)
common logarithm
log x
log10(100.0)
returns
2.0
sin(x)
sine
sin x
sin(3.14…)
returns
0.0
cos(x)
cosine
cos x
cos(3.14…)
returns
-1.0
tan(x)
tangent
tan x
tan(3.14…)
returns
0.0
ceil(x)
ceiling
x
ceil(2.5)
returns
3.0
floor(x)
floor
x
floor(2.5)
returns
2.0                     

No comments:

Post a Comment