Professional Documents
Culture Documents
National University of
AlRIBAT
()
Khartoum Branch
Structural programming
C language
!"
Search in the c programming
language
:
:
:(Introduction)
: ! "#
1
*. %& &/, $! 0 & *. -& ,
$! %&' ( ) * +#
!!) 0 0 ' )2 (345 & , (67 $! *
8
:(C language)9& 6
;# #@' ;
* !'' <4
' =>? : "5 6 9:
(A4"
; 5 (4 /#"
:9& 6 34', (@8
Unix C 84/ $D8 "# c 6 /45 *@/3 C8 , 14&4' 02 0 2 $B
52 0 / GH I ! %!6 14 ' 1
* 6 (E: 34 F23 GH
O82, .c 6 PQR. 1972 $ 9) .B
OB, *), LMN B J (#2 K5
3@/3 0'3 !BQ5 $B 9 BCPL 6 0 @ !&S8 12, bI
6 0 @
GH Basic combined programming language 0 (T *:, 1967 $
$ 9) 14&4' 02 :/45 $B 9 ;8# U48 4: 06 05 PS 12
Bell 2 9) / 12 GHBell#T % 0 BH EM GH 1969
X, C
4: /F"8W 6 9)B
9/ VE, c 12, telephone
Z5 B( ! YS7,) 0/5, C8 0 2 37
1978$ *), C 6 !&' #
!+ [2
The C Programming Language
K&R C T&+5 , [ 12, ! * J\ #/ VE,
6 I ]2 1
5 8
E : &' 9) #&, (Kernighan&ritche)
_#7
*H ST ^&8 9) I,, ;# /4' *. <
VE, #2 @5 9&
c6 B T&8 Z/' *. <
E:, !`5 J )4 > ^&+ X' 0 2
(T *:, ANSI c[ O, 9& 6 T&+ PQR. %'1989$ 9)
/N +R4 " <Standards Institute American National 0
%' / , D+, / /N +R4 +" 05 1,5, /
3M *:,ISO[ O, % L
8
ZT 9) B c6 PQR.
0 *@ a5 ST O82,International Organization for Standization
:;F ( C 6, K&RT&8
<4& * !T5 ; * 9& 6 <4
':Flexibility8, b1
(6@ %D8 "5)aST+
-F" 3 K5 52 b2
U48
ZT * K8# ES+', \' 0 /:portability+ 5B b3
(F!\N
:K8#
,
K# 45 O#2 (Source code); 0 4" Z74 2 4:
ES+ 5B ;"5 Z74
: ( c5 K8# /, (Executable software)
V3 Z L@8. !) %/:K8# 52 H*
:(Source code)V3 Z
O#2, + ! LN *
\4' 9 ,N ,
; 0 & 4:
1&8W 6 0 #/> 65
e 6 *. K8# \' !) %/,:(Compiling)\ H*
:(Compilers);\
6 *. 9 <4& 6 0 V3 Z /4
5 $4' K5 0 (3# 9:
* <4
/ VE Object file *f6 Z XE5 "+ (*8N <4&)e
V3 Z ; 5 ;'
:ES+ H*
Linkerg5
0`' 9 f ;S J K8# *f6 Z g53 * / K85 4:
VE Executable file VES+ Z 4' 9) T& # I,
K8# -!+ K-+ * <4
/
:C 6 $ !
Header files
Preprocessor Directive
Main Function
equal to
0 100>=9 >= greater than or ,&/ ,
0 #2
equal to
};24# 4:,
@5 _f4
if ( condition)
{
statement 1;
statement 2;
statement n;
}
else
{
statement 1;
statement 2;
statement m;
}
/' 5 z5& K8# 4: 9 I],
,
c"+5 /' L . 0 K8# 0 X, };245 _# K-+ ;3#
+` [4
I i85 S' 3 ,
c"+ H 9) 1000 9 U4" 3# 5 /4m #&+
[&H 0 /
.3 /4m #&+
;/ [&H i+ / K85 bo5 – X+ R B i8 +f) 4
U4" *
, o,@ 0 !5 0 , `/
R (3# $T&8
vE: 9) }
0 h+
MR@ (3# z/ ,
. K-+
if ( condition –1)
statement –1;
else if ( condition-2)
statement-2;
else if( condition-3)
statement-3;
………..
else
statement-n;
:I]2,
:#H K85
#include<stdio.h>
#include<conio.h>
Main()
{
Float num1,num2;
Char op;
Printf(“\n type num1,op,num2;
scanf(“%f%c%f”,&num1,&op,&num2);
if(op==’+’)
printf(“\n sum=%f”,num1+num2);
else if(op==’-‘)
prinf(“\n dub=%f”,num1-num2);
else if(op==’*’)
printf(“\n multi=%f”,num1*num2);
else if(op==’/’)
prinf(“\n div=%f”,num/num);
else
printf(“ERRoR”);
getch();}
~B K85
#include<stdio.h>
#include<conio.h>
Void main()
{ int dd/mm/yyyy,dd2/mm2/yyyy2;
Printf(“the year now:”);
Scanf(“%d”,& dd/mm/yyyy);
Printf(“the year you born:”);
Scanf(“%d”,& dd2/mm2/yyyy2);
Printf(“you have %d years!\n”, dd/mm/yyyy - dd2/mm2/yyyy);}
If(dd/mm==dd1/mm1)
Printf(“happy birthday to you”);
}
:switch (3#
;3# 4" ES+' *) #&' Mif….else 0 /5 14 ' 1 0 /
* 3M /, $TQ H ; 4" 0 0 +
:6 EM',switch (3# M 4\4 9#
switch (variable)
{
case value1;
statement 1;
break;
case value2;
statement 2;
break;
case value 3;
statement 3;
break;
……………
default:
statement;
}
3T 6 !/ (switch) 5
#/ -# 3T 1p) <8 2,
V4
/ #2 {45 ~4B X 9/, }vES+' % VE 3T iB
' VE,
0 {45 2 , H, -# 0 3M ]/ !+ 2 (67 ;245 iM
]' 9, - 3T 6 5 4# (case) 5
#/ -# ;245
."+ (3# 9'' X 5, - o@
0 '4# J+ 4: vE: 0 =6, (break) 5 /# {45 %T/,
0:E 3#/, *4 :4 #/> (3# vE: ,#' B, "+ (3# ES+'
;3# 5 ES+ '4# J)/ ) ] I4 o@ z
/ %
: _ Iq
K-+
'4# ' I -# 3T (3# 1
9: Iq& E: 0 5",
/!8 5, (break) 5 8& $F E }!) o V
z
' 5 ZB45
'4# :ES+/ ;3#5 ,
(3#5 4# (default) 2 9'' -# ;245
.5& o,@ 0 V
z
' $ H 9)
(H,
: 6
H, 35 1+
H, 35 (/F ++
:for3#
,
) 0
3 for
$T&' * t
' < /H (3# *:
D8 )
7+ Gk 9.
t
', ; 0 ( 4 0 4"
: (9 @
for ( counter statement; condition; step)
:1 GH
3 ; "&' 9: Sh, ( counter ) b
-B 3 D/ . 3 /!8
/ VE o@, (condition) o@b
.o@ 9S+/ *H
.3 ;
' 9 9:, (step)gT -3 b
:,
for(exp1;exp2;exp3)
1 R 3 &/, (#2 , &5) :5 (3# I, 3 5 for $4',
_
7 (exp2,(condition))
forz
$T5 i) +B "85 _f4/ 9 @,
#include <stdio.h>
main()
{
int counter;
for ( counter=1;counter<=20;counter++)
printf(“%d”,counter);
}
!+5 045 4# ( for ) % 5 ;
5 for
1
"8 z5& K8# 0,b
(3# R4+ 7S Q !+5 S' ;3# kQk
(3#, 9) -5 1FT' 94 b
20V,&' ,
0 B
B 1
o@ +:, o@ 9: 8] b
1 35 F/ K8# E: 9), }(4T
' 9!) ]] (3#
b
.
!) ES+' ( 2
2*. 1 0 $B #R i+ K+/ z5& K8#,b
:DHQ
}R4+ 7S5 !`5 0 S' 1
"/ for
84 kQ] ;3#b
for
/5 9' 9 (3# I# %/
0 ]2
3 ' H 9)b
(3# 9: z5& I])
printf ( " %d",counter;)
: nested for Mfor
: @ EM', ]2 , (3, * !M5 @' (#2 (3, 0 ( 3#
For(exp1;exp2;exp3)
For(exp1;exp2;exp3)
For(exp1;exp2;exp3)
1-12 0 [` I,M EM8 I]2,
#include<stdio.h>
main()
{ int i,j;
for(i=1;i<13;i++)
for(j=i;j<13;j++)
for(“%d*%d=%d”I,j,i*j);
}
:)while ) while loop
ZB4/, ; 0 $4 stm ;3# 4" , (3# 3 $T&'
while (3# *) 4\4 o * 3
" 6
While(exp)
Stm;
*. 1 0 # while
$T _f4/ 9 @5 _f4 I],
:2
#include <stdio.h>
main()
{
int counter=1;
while ( counter <=20 )
{
printf(“%d”,counter);
counter++;
}
}
:
0 K'+ uT ++ / z5& I] 0
t3M %' -# uT'
M %' (/A
:do…..while /3
while ] 0 o@ Y), ( 1 ]2 ;3# 0 4", o 3 $T&'
: 6
do
{
statement 1;
statement 2;
.
.
statement n;
}
while ( condition
:3 ' [4 ;3# ES+' !8
do-while/3
* D
%:
,
z
> o@ 12 4, *H * (H, (
0
9) 2 i#B C, ES+ 5 %/ o@ 0 z
1
X &S',
05&
_
7 exp 1 R stm 3 ' %/
#2 , &5 stm 14 ' 1 0 /
:while&do….while 05 P6
%k , (3# ES+' do..whi.le 0 , (3# ES+' %k , o@ #T' while 1
o@ #T'
(H, ( (3# ES+' B * !8 <
:I]2,
# include<stdio.h>
# include<conio.h>
main( )
{
char pass[10];
do
{
printf(“\n enter password: “ );
scanf(“%s”,pass);
}
while(strcmp(pass,”dahe”)!=0);
}
:;DHQ
5 L+k
!D' 4 & 2 +:
12 p) string )H (3# U48 0 0/6 i835 $4' : strcmp( )
S7 !+5 PS 12 05 0/6
:-& 2 K8# /'
:(@ * $T& ه/ * & 2 3, ه$ )
# include<stdio.h>
# include<conio.h>
main( )
{
chat ch;
char pass[10];
do
{
textcolor(WHITE);
textbackground(BLUE);
cprintf(“\n enter password: “ );
textbackgrounf(WHITE);
cscanf(“%s”,pass);
}
while(strcmp(pass,”dahe”)!=0);
}
FUNCTION I,
i5 : %/ % ! uT/, (
! V4/ 9 ) K85 0 (3#
MMAIN 4" * 9& 6 # V4
' <M V M ,
] I, 0printf,scanf,getchar) > 7M L+5 0 / 2
.6 # 9) ()4
#include<filename.h>
Finclion declarations;…………………….(1)
Main()
{
Statements;
Function calling;………………………..(2)
Statements;
}
Function definition()…………………….(3)
{
Statements
}
V+ K8# :' 9 (int,float….) U48:type argument
, B ' B value # 4# reurn (A4"
$T5
. void ( U48 14 /
%/ !QM 0 ; /
' i) %/, funetion definition Z/' -3
=6 /'
void
: L
;Q 1,5 , ;Q5 I, L %/ -
52 $ < void line2(void) ] ;Q 1,5 14 ' -
~4B
05 %B
:;Q5 L S2 _f4/ K85 -
# include < stdio.h>
# include <conio.h>
void line3(int no)
main( )
{
clrscr( )
line3(30);
printf(“ ** Allah the god of all world ** \n “);
line3(70);
}
void line3(int no)
{
int j , no;
for(j = 0 ; j <= no ; j++ )
printf(“ * “ );
printf(“\n”);
}
%/ ( 2 *), no4:, _
7 U48 0 H, ! +: : DHQ
. L + X, ST B I3
:;n65 L
i&S8 K8#5 (4\4 5k %B U48 0 ;Q5 L 0
0 , $T& 0 !B #&' ;6 ;Q vE: 14 ' 1 0 / `/
,
L . ( ( 2 *) ;6 QM, 6' H *) S/ E:, K8# M
)K8# J *) 8,
:
n
7 ;n2 Qk 0 #2N n /
K85
# include <stdio.h>
/* determine the largest of three integer quantities */
main( )
{
int a, b, c, d;
/* read the integer quantities */
printf(“\n a = “);
scanf( % d “ , &a );
printf(“\n b = “);
scanf( % d “ , &b );
printf(“\n c = “);
scanf( % d “ , &c );
/* calculate and display the maximum value */
d = maximum( a, b );
printf(“\n \n maximum = % d , maximum(c ,d ));
}
/* determine the larger of two integer quatities */
maximum(x ,y )
int x ,y;
{
int z;
z = (x >= y ) ? x | y;
return(z);
}
:: DHQ
GH|R@ $!S Q %
,
0f 0
3#M test (3# (x > = y )
ifIq 0 (3#
Else 0 (3# |
> O82 ., x EM/
7 (x >= y ) 3#M 12 . *+5
y EM/
7
Reference Search G
# J\
:
c &c++I 65 "# [2b1
C 65 "# 9) b2
;8, , [4
$4 @ &b3
/# /,b4
c6 * b5
c 65 "# *) b6
c-in7-daysb7
The C Programming Languageb8