4. type int ,
float , char , double , void
void
int
function_name
type parameter parameter
, N
parameter void
{
location variable declaration
statement_ ; statement_ ; ... statement_N
return(value);
5. F N T N INC
U C IO S
CS A D R
TNAD PO RM E
R G A MR
LIBRARY DF E F N T N
E IN D U C IO
1. User-defined
Function)
2. Standard Function)
include directives header file
7. type
type int, float, char
double int
type void
function_name
type1 arg1, type2 arg2,…, typeN argN
argument 1, 2, 3,…, N
void
{
}
local variable declaration
local
statement(s) 1
; (semicolon)
return(value)
value ()
8. #include<stdio.h>
#include<conio.h>
void one(void); /* function Prototype
void two(void); /* function Prototype
void main(void)
{
clrscr();
one(); /* call one() */
two(); /* call two() */
printf("nPress any key back to program ...");
getch();
}
/* one function */
void one()
{
int a=5, b=7;
printf("A = %d, B = %dn",a,b);
}
/* two function */
void two()
{
float p=4.5, q=3.5;
p+=q;
printf("P = %6.3f, Q = %6.3fn",p,q);
}
20.
#include<stdio.h>
#include<conio.h>
int calculate(int, int);
void main(void)
{
int p=3, q=4, r;
clrscr( );
r = calculate(p,q);
printf("P = %d, Q = %d, R = %dn",p,q,r);
printf("nPress any key back to program ...");
getch();
} /* end main() */
int calculate(int p, int q)
{
return (p+q);
}
21. 3 int calculate (int, int);
argument 2 int
int
caculate( )
8 r = caculate (p, q);
caculate( ) p q
caculate( )
13 16
13 16 caculate( )
p q
main( )
r
9 p, q r
25.
/* 7th Sample Program: Local vs Global Variable */
#include<stdio.h>
int ans = 0;
int inc_one(int); /* function prototype */
void main()
{
int a = 3;
ans = inc_one(a);
printf(“Answer is %dn”, ans);
}
/* function definition: return x+1 */
int inc_one(int x)
{
int ans;
ans = x + 1;
return ans;
}
26. ans
(main)
ans
a
inc_one x ans
ans
ans
inc_one
ans
inc_one ans
27.
PROGRAM AA;
VAR NUM:INTEGER;
PROCEDURE A;
BEGIN
NUM:=NUM*10; RUN
WRITELN(‘NUM*10 = ‘,NUM);
END; NUM*10 = 50
VAR ANY:INTEGER;
PROCEDURE B; NUM = 124
VAR NUM,CNTR:INTEGER;
BEGIN
CNTR = 122
NUM:=124; BACK TO MAIN
WRITELN(‘NUM = ‘,NUM);
CNTR:=122; NUM = 50
WRITELN(‘CNTR =’,CNTR);
END;
BEGIN {MAIN PROGRAM}
NUM:=5;
WRITELN(‘IN MAIN’,’NUM = ‘,NUM);
A;
B;
WRITELN(‘BACK TO MAIN NUM = ‘,NUM);
END.
28. - NUM
output output program
A
- NUM, cntr program B B
NUM NUM
NUM NUM=5 A
10 50 B 124
124 50 NUM
- procedure B ANY
procedure A procedure B
- B A A B
32. math.h
double
double
sin(x) sine x
cos(x) cosine x (radian)
tan(x) tangent x
(radian)
sqrt(x) x x
exp(x) ex e 2.718282
pow(x,y) xy
log(x) log e natural logarithm
x
log10(x) log 10 x
ceil(x) x x