Professional Documents
Culture Documents
Lecture 22 (Pic)
Lecture 22 (Pic)
PROGRAMMING IN ‘C’
C STANDARD LIBRARIES AND BASIC
ALGORITHMS
C99 EXTENSIONS
C99 (previously known as C9X) is an informal name for ISO/IEC
9899:1999, a past version of the C programming language
standard.
STANDARD LIBRARY FUNCTIONS:
Standard Library Functions are basically the inbuilt functions in the
C compiler that makes things easy for the programmer.
As we have already discussed, every C program has at least one
function, that is, the main() function. The main() function is also a
standard library function in C since it is inbuilt and conveys a
specific meaning to the C compiler.
In order to access the standard library functions in C, certain header
files need to be included before writing the body of the program.
HEADER FILE MEANING ELUCIDATION
Standard library Used to perform standard utility functions like dynamic memory
<stdlib.h>
header allocation using functions such as malloc() and calloc().
Used to perform functions related to date and time like setdate() and
<time.h> Time header getdate() to modify the system date and get the CPU time
respectively.
1 size_t
This is the unsigned integral type and is the result of the sizeof keyword.
2 clock_t
This is a type suitable for storing the processor time.
3 time_t is
This is a type suitable for storing the calendar time.
4 struct tm
This is a structure used to hold the time and date.
<stdarg.h>
The stdarg.h header defines a variable type va_list and three
macros which can be used to get the arguments in a function
when the number of arguments are not known i.e. variable
number of arguments.
A function of variable arguments is defined with the ellipsis (,...)
at the end of the parameter list.
Library Variables
Following is the variable type defined in the header stdarg.h –
1 va_list
This is a type suitable for holding information needed by the three
macros va_start(), va_arg() and va_end().
<setjmp.h>
The setjmp.h header defines the macro setjmp(), one function
longjmp(), and one variable type jmp_buf, for bypassing the
normal function call and return discipline.
Library Variables
Following is the variable type defined in the header setjmp.h –
1 jmp_buf
This is an array type used for holding information for
macro setjmp() and function longjmp().
<unistd.h>
The <unistd.h> header defines miscellaneous symbolic
FINDING FACTORIAL-
Factorial of a positive integer n is product of all values from n to
1. For example, the factorial of 3 is (3 * 2 * 1 = 6).
Algorithm
Algorithm of this program is very easy −
START
Step 1 → Take integer variable A
Step 2 → Assign value to the variable
Step 3 → From value A upto 1 multiply each digit and store
Step 4 → the final stored value is factorial of A
STOP
FIBONACCI SERIES:
Fibonacci Series generates subsequent number by adding two previous numbers.
Fibonacci series startsfrom two numbers − F0 & F1. The initial values of F0 & F1 can
be taken 0, 1 or 1, 1 respectively.
Fibonacci series satisfies the following conditions −
Fn = Fn-1 + Fn-2
So a Fibonacci series can look like this −
F8 = 0 1 1 2 3 5 8 13
or, this −
F8 = 1 1 2 3 5 8 13 21
Algorithm
Algorithm of this program is very easy −
START
Step 1 → Take integer variable A, B, C
Step 2 → Set A = 0, B = 0
Step 3 → DISPLAY A, B
Step 4 → C = A + B
Step 5 → DISPLAY C
Step 6 → Set A = B, B = C
Step 7 → REPEAT from 4 - 6, for n times
STOP