C Language
C Language
* - : C C -:
- : .
: Structured Language C . .
- - : .
- : C
ANSI
C> # include < stdio .h
) ( main
{
; ) " printf ( " hello egypt
}
> # include < h . include
- ) ( main { } .
. - ) ; (
/* */
} {
* -:
Data Type
) ( integer ) ( . float
* byte -:
) ( char
) ( int
) ( long
) ( float
e- 38 e + 38
e -308 e+308
) ( double
- :
- : .
- : ) ( .
) : (Long
: 5 .33 - : .
* - : -:
-
HP hp
.
* - :
C Variables C ++
; int a
; float
* operators
- arithmetic operators
+
addition
Subtraction
multiplication
division
- -:Relational operators :
>
10>8
less than
<
10<8
equal to
==
==
not equal to
=!
!=
=<
< = 8
=>
10 > = 8
greater than
- Logical operator
AND
&&
OR
||
1 0 < 8 || 7 < 8
NOT
) ! (10 = = 8
- Assignment Operators
A = a +5
A=a5
A=a+5
A=a/3
A+=5
A-=5
A*=5
A/=3
11
1
30
2
- Decrement &increment
A=a+1
A ++
A=a1
A --
- %
)
a = 5 C = a % 2 1 = 5 / 2
* )(* printf
:
# include )( printf stdio.h #
: new line
welcome
with
compusciene
) (printf
\n
new line
) printf ( " \n
\t
) ( Tap
) print f ( " \t
\b
Backspace
\xdd
hexadecimal
\ddd
octol
) ( each d represents a digit
double quate
\a
) (
* :
/ * program name 1 * /
> # include < stdio.h
) ( main
{
; ) printf ( " \n this text display in new line
; ) printf ( " \n word1 \t lab1 \t tab2
; ) printf ( " \n bell \a bell \ b
; ) \ printf ( " \n this line display quotations
; ) printf ( " \n
}
* :
)( print f
; ) printf ( " % d , a
; ) printf ( " % f , b
% . .
%d
)printf ( " % d , - 10
) printf ( % p , 507
) (
) printf ( % c , a
%u
(
) (unsigned decimal integer
hex
%o
) printf ( % s , is
String
%x
Qctal
) printf ( % u , 1
) printf ( % x , af
) printf ( % o , 67
*
/ * program name 2 * /
> # include < stdio.h
) ( main
{
; int a , b , c
; float f
; long t
; char ch = y
; " char name [10] = " aly
;a=5
; b = 10
;c=a+b
; ) printf ( \n c = % d , c
; ) printf ( \n f = % f , f
; ) printf ( \n name = % s , name
; )printf ( \n ch = % c , ch
; ) printf ( \n t = % ld , t
}
* *
) ( main {
7 , 6 , 5
ch ) ( char y
name
Aly
A , B C
{
: : % 3F 534.6735
534.674
* ) ( *Scanf
) ( Print f
:
a , b , c , r , s , t , name
)( printf enter your name
) ( scan f name
# & #
: &a a a
&
* -:
welcome ahmed
c = a + b = 15
t = r + s = 50
:
/ * function heading */
/* variable declarations */
/* output statement */
/* input statement */
/* assignment statement */
/* output statement */
* *
) ( ) - : getchar ( stdio .h
enter
; char a
; ) ( a = getchar
; ) printf ( % c , a
- ) ( ) - : getche ( conio .h
) ( getchar enter
; char a
; ) ( a = getche
; ) printf ( % c , a
) ( ) : getch ( conio.h
enter
; char a
; ) ( a = getch
; ) printf ( % c , a
* ) ( ) : putchar ( stdio.h
-
) ( gets string
;]char name[20
; )gets (name
) ( gets Name
* ) ( * puts stdio.h
- string
) abs ( i
include
stdlib.h
) log ( d
math.h
) pow ( d1 , d2
d1 d1
math.h
) labs ( e l
) sin ( d
d
math.h
math.h
) sqrt ( d
math.h
) strcpy ( s1,s2
s2 s1
string.h
main .
- :
) (
Loop
- : for
:
: initial value
: condition
: increment
:
> # include < stdio.h
) ( main
{
; int i
) for ( i = 0 ; i < 10 ; i ++
; ) printf ( \ n i = % d " , i
}
* : For {
} .
loop
Loop .
:while while
:
) While ( condition
{
; statement 1
; statement 2
}
) While ( condition
; Statement
} { ) (
False . .
False
: While
> # include < stdio.h
) ( main
{
; int n , count = 1
; float x , average , sum = 0
; ) " ? printf ( how many number
; ) scanf ( % d , & n
; ) while ( count < = n
{
; )" = printf ( x
; ) scanf ( % f " , & x
; sum + = x
;count ++
}
; average = sum / n
; ) printf ( " \ n the average is % f " ; average
}
* For * While
- For
while while
- : Do while do while
. Do
) ( True
False
(
* : IF IF ) (
) if ( condition
; statement
) ( condition
if {
} :
) if ( condition
{
; statement 1
; statement 2
}
* if : if :
) if ( condition
) if ( condition
) if ( condition
.
* : if else :
) if ( condition
{
statement 1
}
else
{
statement 2
}
) ( statement 2 if .else
.
* : if . else if
: IF - :
;i=5
; ) if ( i < 5
; ) " printf ( i less than 5
) if ( i = 5
; ) " printf ( " i equal to 5
) if ( i > 5
; ) printf ( i greater than 5
) if ( condition
; statement 1
) else if ( condition
; statement 2
) else if ( condition
; statement 3
:
;I=5
) if ( i < 5
; ) " printf ( i less than 5
) else if ( i = 5
; " printf ( i equal to 5
) else if ( i > 5
; ) " printf ( " i greater than 5
: -:
> # include < stdio.h
) ( main
{
; float num1 , num2
; char op
)while (1
{
; ) " printf ( type number , operator , number \ n
Switch . case -
Switch
Switch
Switch .. case :
#include < stdio.h>
main ( )
{
float num1,num2;
char ch,op;
do
{
printf( \in type num1 op num2: ) ;
scanf( %f %c %f , &num1,&op,&num2);
switch (op)
{
case +;
printf ( "sum = %f ", num1+num2);
break;
case -;
printf ( "sub = %f ", num1-num2);
break;
/* void main(void) */
;* case
;)printf ( "mul = %f ", num1*num2
;break
;case /
;)printf ( "div = %f ", num1/num2
;break
default:
;)printf\n unknowen operator .
}
;) printf(\n Again (y/n):
}
while (( ch=getch())== y ):
}
: switch .. case
) ( menu
break switch
( goto
>#include <stdio.h
) (main
{
;char ss
ss:
;)printf(\t ALLAH
;goto ss
}
- : goto
- CTRL+C
** **
) ( ) ( : clrscr conio.h
) (clrscr
) ( ) ( : gotoxy conio
x y -
) (gotoxy
: 30 )gotoxy(30,10
) ( ) ( : textcolor conio.h
-
)textcolor(color no
)textcolor(color name
.
BLACK
BLUE
GRCEN
CYAN
RED
MAGENTA
BROWN
LIGHTGRAY
DARKGRAY
LIGHBLUE
LIGHTGREEN
LIGHTRED
LIGHTRED
LIGHTMAGENTA
YELLOW
WHITG
:
-
: $ %
f=p(1+i)n
I p n
:
** **
#include <stdio.h>
#include <math.h>
main()
{
float p,r,n,i,f;
/* read input data */
printf( please enter a value for the princepal (p) : );
scanf(%f k &p);
printf(please enter a value for the interest rate( r) : );
scanf(%f, &r);
printf(please enter a value for the number or year ( n) : );
scanf(%f, &n);
/*calculate i , then f */
i=r/100
f=p*pow((1+i),n);
/* write output */
-
ax2 + bx +c = 0
4 ac
=X
2 a
** **
># include <stdio.h
># include < math.h
/* real roots of a quadratic equation */
) (main
{
;float a,b,c,d,x1,x2
/* read input data */
;) =printf(a
;)scanf(%f,&a
;) =printf(b
;)scanf(%f,&b
;) =printf(c
;)scanf(%f,&c
/* carry out the calculations */
;)d=sqrt(b*b 4*a*c
;)x2=%e ,x1,x2
:
;)x1=(-b+d)/(2*a
;)x2=(-b-d)/(2*a
/* write output */
printf(x1= ,%e
}
: %e
x 1
1 x 1 2 1 x 1 3 1 x 1 4 1 x 1 5
( )+
( ) +
( ) +
( ) +
)
x
2 x
3 x
4 x
5 x
* -:
** **
x 1
)
x
(=y
(= u
u 2
u 3
u 4
u 5
+
+
+
2
3
4
5
y = +
># include<stdio.h
># include<math.h
) (main
{
;float u,x,y
/* read input data */
;) = printf ( x
;) scanf( %f ,&x
/* carry out the calculations */
;u= (x 1)/x
;y=u+pow(u,2.)/2+pow(u,3.)/3+poe(u,4.)/4+pow(u,5.)/5
;) y =%f , x,y
printf(x= ,%f
}
># include<stdio.h
># include<conio.h
) (main
{
;]char pass[10
do
{
;) printf(\n enter password:
;)scanf(%s,pass
}
;)while(strcmp(pass,dahe)!=0
}
) ( : strcmp string
-:
) (
># 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);
}
:
/* count characters and word in a phrase typed in */
# include <stdio.h>
main( )
{
int charcnt=0;
int wordcnt=0;
char ch;
printf( type in a phrase : \n );
/* read characters and quit loop on [ return ] */
while((ch=getche())!=\r);
{
charcnt ++
/* count character */
if(ch== );
/* space ? */
wordcnt++;
}
printf(\n character count is %d ,charcnt );
printf(\n word count is %d , wordcnt );
}
printf( )
) (puts
) (scanf
) (gets
)(getch
) (getche
) (clrscr
) (gotoxy
) (textcolor
) (textbackground
cprintf( ) , cputs
cscanf( ), cgets
FUNCTION
C -:
) ( Built in Function ) ( printf ) (scanf
) ( -:User Function
-
: .
- :
-
:
># include < filename
;function declarations
) (main
{
function1
function2
}
function1
{
----------}
function2
{
----------}
-:
) (
) (
:
>#include <stdio.h
>#include<conio.h
;)void line2(void
) (main
{
) (clrscr
) (line2
;) printf( ** Allah the god of all world ** \n
) (line2
/* end of main( ) function */
}
)void line2(void
{
;int j
;)for(j=0;j<=40;j++
;) * (printf
;) printf(\n
}
) ( line2 ) ( line2 -:
: function declaration
) ( main
: ) ( main
function coling ) ( line2
: ) ( .main
function definition .
**
** Function Type
int function
float function
string function
structure
void function
struct function
;int s
;s=a+b
;return s
}
** **
) ( sum int void .
x ,y ) (
- -:
a x .
b y .
a b s
s return
) z = sum(x,y . z = s
:
.
int int
float float
) (return void
** **
-
- ) void line2(void
* *
># 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
}
** : .no
.
** **
) (
*
># 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
}
: ) |? ( -:
(x > = y ) -
test
if | - Else
) (x >= y x
**
># include<stdio.h
/* calculates difference between two times */
) (main
{
;int mins1 , mins2
;) printf( type first time ( from 3:22 ):
;)(mins1=getmins
;) printf( type second(later) time
;)(mins2=getmins
;)printf( Difference is %d minutes. , mins2-mins1
}
/* getmins function */
/* gets time in hours : minutes formal */
/* return time in minutes */
) (getmins
{
;int hours, minuts
;)scanf( %d : %d , &hours , &minutes
;)return(hours * 60 + minutes
}
* int -:
float
.
float float
># include <stdio.h
># include < conio.h
) float add( float x , float y
) (main
{
;float no1, no2
;) printf(\n enter no1 , no2 :
scanf( %f ,%f , &no` ,&no2 ):
**
# include < stdio.h>
/* tests use of external variables */
int keynumb;
main( )
/* external variables */
{
printf( type keynumb : );
scanf(%d , &keynumb );
addeven( );
negative( );
}
/* checks if keynumb is odd or even */
oddeven( )
{
if (keynumb % 2 )
printf( keynumb is odd. \n);
else
printf( keynumb is even. \n);
}
MACROS
function
)
(
: C
-:
- #define
directive preprocessor *
#define
a 5
># include<stdio.h
# define sum(a,b) a+b
# define mul(x,y) x*y
) ( main
{
;int v1=5 , v2 = 10
;)printf(\n\n sum(v1,v2) = % d,sum(v1,v2
;)printf(\n\n mul(v1,v2) = % d,mul(v1,v2
}
-:
2 define sum a,b a+b
3 x,y x*y
: a,b .
) ..
(
* -: -:
: source code .C
: compilation
.obj
: object
linking .exe
-:
- .
- compilation object
linking
-
) 7 .
15 ) sum(v1,v2
( 15
-:
-
-
- .
:
># include<stdio.h
# define pi 3.14159
) ( main
{
;)float area(float
;float radius
;) printf(enter radius sphers :
scanf(%f, &radius):
;))printf(area of sphere is 2f,area(radius
}
/* returns ares of sphere */
)float area(rad
;float rad
{
;)return(4*pi*rad*rad
}
ARRAYS
*
char int float
.arrays
** **
array .
int
. float .
* * .
) ( :
) (
) (
: 120
. float
:
]float salary[120
** -:
A[ 2 5 9 12 15 ] :
A
** **
- ]
: 75 3 student
:
student[3] = 75
38 salary :
]a = salary[37
{
;)printf( please enter salary for employee %d, count+1
;)]scanf(%f, &salary[count
}
;)printf(\n\n salary average is : %f, average/max
}
-:
10 .
- ]float salary[max
10 ]float salary[10
average .
count
** **
} int marks[5] = { 12 4 7 9 11
int
* **
.
-
int marks[ ] = { 5 9 4 10 7 } :
{ .
** **
# include <stdio.h>
/* calculate the average of a numbers , the compute deviation of each number
about the average */
main( )
{
int n , count ;
fliat avg, d , sum=0 ;
/* read in a value for n */
printf(\n how many numbers will be average? ;
scanf(%d, &n);
printf(\n);
/* read in the numbers and calculate ther sum */
for(count = 0 ; count < n count++ )
{
printf(i = %d x= , count+1);
scanf(%f, &list[count]);
sum+= list[count];
}
/* calcuate and write out the average */
avg = sum/n;
printf(\n the average is %5.2f\n\n , avg);
/* calculate and write out the deviations about the average */
for(count = 0 ; count < n ; count++)
{
d=list[count] avg ;
** **
# include<stdio.h>
# define size 100
/* reorder a one-dimensinal, integer array from smallest to largest */
main( )
{
int i , n , x[size];
void reorder(int n , int x[ ]);
/* read in the a value for n */
printf(\n how many number will be entered ? );
scanf(%d, &n );
printf(\n);
/* read in the list of number */
for(i = 0 ; i<n ; i++)
{
printf(i = %d x = , i+1);
scanf(%d, &x[ i ]);
}
/* reprder all array elements */
reorder(n , x )
/* display the reordered list of numbers */
print(\n\reordered list of number :\n\n );
for(i=0;i<n; i++)
printf(i=%d x=%d\n, i+1 , x[ i ] );
}
int i, item ,temp;
* *:
- ]int a[5] [10
5 10
: for
* :
= ]int a[3][4
{
{4,5,7,8 },
{3,2,4,5},
}{7,8,9,6
;}
: 0,0 4 0,1 5
- }
} {
:
;}int values[3][4] = {1,2,3,4,5,6,7,8,9,,10,11,12
0,0 1 ] values[0][0 0,1 2
]values[0][1
:
># include <stdio.h
# define stud 3
# define marks 10
void main (void)
{
int student[stud][marks];
int c1 ,c1 ;
for(c1 = 0 ; c1 < stud ; c1++)
for ( c2 = 0 ; c2 < marks ; c2++)
{
printf ( enter marks: %2d for student %2d : , c2+1 , c1+1 );
scanf ( %d , &student[c1][c2]);
}
for(c1 = 0 ; c1 < stud ; c1++ )
for(c2= 0 ; c2 < marks ; c2++)
printf( student [%2d] , marks[%2d] = %d\n , c1+1, c2+1 , student[c1][c2]);
}
student :
int student[stud][marks];
. for . .
.
: *
c[i][j] = a[i][j] + b[i][j]
# include <stdio.h>
# define mrow 20
# define mcol 30
/* caluculates the sum of the elements in two tables of integers */
void main (void)
{
int mrow , mcol;
/* array definitions */
int a[mrow][mcol] , b[mcol][mcol] , c[mcol][mcol];
/* function protyotypes */
void readinput(int a[ ][mcol],int nrow , int ncol);
void computesum ( int a[ ][mcol], int b[ ][mcol] , int c[ ][mcol], int nrow ,
int ncol);
:
a ,b ,c row - .
ncol row -
col -
* -:
13
11
12
10
17
16
15
14
12
11
10
21
20
19
18
2
3
-:
how many rows? 3
how many columns? 4
first table :
enter data for row no. 1
1
2
3
4
enter data for row no. 2
5
6
7
8
enter data for rpw no. 3
9
10
11
12
second tables :
enter data for row no. 1
10
11
12
13
enter data for row no. 2
14
15
16
17
enter data for row no. 3
20
21
19
18
* * ) ( array of string
string
* *
** char :
]char name[80
name ) c )(null
**
** -:
- .
printf gets .
** -:
?# include<stdio.h
)void main(void
{
]char namr[80
;) printf(place enter your name :
;)gets(name
;)printf(welcome , %s , name
}
* :
name gets
'name[0] = 'a
;]ss = name[15
** **
) ( null
* *
># include <stdio.h
)void main(void
{
;char strin[ ] = hello
;))printf(character array = %s , its length = %d \n, strin , sizeof(string
}
* :
string hello char string[ ] = "hello - printf
:
4
5
6
l
o
\0
** -:
3
l
2
e
1
h
># include<stdio.h
)void main(void
{
;int count
char string[ ] = hello
)for(count = 0 ; count < sizeof(string); count ++
;)]printf( string[%d] = =%d %c \n , count, string[count], string[count
}
string for
.-
string
-:
String[ 1 ] = 101 e
String[ 3 ] = 108 l
String[ 5 ] = 0
=
h
l
o
String[ 0 ] = 104
String[ 2 ] = 108
String[ 4 ] = 111
** **
) ( -:
strlen
) ( -:
- c .
- strcpy .
string
strcpy .
) ( -:
strcat strcat(string1 , string2) : srcat string2 string1
string1 string2
) ( :
-
result -: strcmp
*
># include < stdio.h
># include <string.h
)void main(void
{
;]char string1[80
;]char string2[80
;int result
;) printf( enter the first string
;)gets(string1
;) printf( enter the second string :
;)gets(string2
;)result = strcmp(string1,string2
) if(result == 0
;) printf(the two string are identical :
else
;) printf(the two string are different :
}
:
strcmp
strcmp
result = strcmp(string1,string2);
* *
# include < stdio.h>
# include < string.h>
void main(void)
{
char string1[80];
char string2[80];
int result , choice;
printf( enter the first string : );
gets(strig1);
printf(enter the second string : );
gets(strung2);
printf(\n enter the function you want: \n
1- strcpy \n
2- strcat \n
3- strcmp \n);
printf(enter you choice : );
scanf(%d , &choice);
switch(choice)
{
case 1:
printf(\n copy second string to first \n);
strcpy(string1 , string2 );
printf(string1);
break;
case 2:
printf(\n merging the two string \n);
strcat(string1 , string2 );
;)printf(string1
;break
case 3:
;) printf(\n comparing the two strings \n
;)result = strcmp(string1,string2
) if(result == 0
;) printf( the two strimg are identical
else
;) printf( the two strimg are different
;break
default :
;) printf(plase enter a number 1-3
}
}
** **
fn int
;)fn(num
* -:
-:
># include < stdio.h
># include <ctype.h
># include <string.h
;) ] [void changetoupper(char string
)void main(void
{
;]char string[80
do
{
;)printf( enter a string to change to upper case \n enter \ quit \ to exit
;)gets(string
;)changetoupper(string
}
;))while(strcmp(string , quit
}
do.while quit
changetoupper .
(strcat
)
) ( ) (
) (strchr
) (strcmp
) (
) (strcpy
) (strlen
) (strupr
**
atof
Atoi
-:
Atol
Strtod
_itoa
_ltoa
) ( Structure
: structure .
) ( . :
) ( char
) ( int
) ( float
structure .
* -:
- -:
struct C
struct
{
;--------------
;--------------
;--------------
;}
-:
struct employee
{
;]char name[40
;]char address[40
;int age
;float salary
- employee ) (
;}
:
;struct employee emp1
emp1 ) ( emp1 86 byte -:
emp1.age
30 age :;emp1.age=30
- a.emp1.salary; :
gets(emp1.name); :
gets
name emp1
* -:
># include <stdio.h
)void main(void
{
struct employee
{
;]char name[40
;]char address[40
;int age
;float salary
}
;) pruntf(enter salary :
;)scanf(%d,&emp1.salary
; printf(\n\n you entered: \n
;)printf( employee name :\t%s\n , emp1.name
;)printf( employee address :\t%s\n , emp1.address
;)printf( employee age :\t%d\n , emp1.age
;)printf( employee salary :\t%f\n , emp1.salary
}
* *
100
-
struct employee
{
;]char namr[40
;]char address[40
;int age
;float salary
;}
]struct employee emp[100
employee emp 100
- .
;emp[4].age=35
-
{
struct booktag
{
char title[40];
char author[40];
int pages;
int year;
char edition;
};
struct bootag book[max];
//
int c ,c1 , result;
char temp[10];
//
for(c = 0 ; c < max ; c++)
{
printf( enter data for record no[%d]\n m c+1);
printf( or enter \ quit \ to end \n\n;
printfenter title : );
gets(boo[c].title);
/* )(
result = strcmp (book[c].title,quit);
if (result = = 0 )
break;
printf(enter author : );
gets(book[c].author);
printf(enter number of pages : );
gets(temp);
book[c].pages = atoi(temp);
printf(enter year of publication : );
gets(temp);
book[c].year = atoi(temp);
printf(enter edition : );
gets(temp);
book[c].edition = atoi(temp);
}
//
printf(record no. %d\n:, c1++);
printf(book title : \t\%\n , book[c1].title);
printf( book author : \t%d\n, book[c1].author);
printf(no of pages :\t%d \n , book[c1].pages);
printf(date of pub. \t%d\n,book[c1].year);
printf(edition : \t%d\n\n ,book[c1].edition);
}
** **
- book
booktag -:*
- 10
for 10 quit
quit
break
;)result = strcmp(book[c].title , quit
if(result = = 0
;break
- strcmp quit
studenttag . - * -:
** ) (
.
.
** **
//
>#include<stdio.h
>#include<string.h
>#include<stdlib.h
struct sudenttag
{
;]char name[40
;int age
;int grade
;}
//
void print(sturct studenttag student)
{
printf(\n\n you entedred : \n\n );
printf(student name: \t%s\n,student.name);
printf(sudent age: \t%d\n,student.age);
printf(student grade : \t%d\n,student.grade);
}
//
struct studenttag getinfo(void)
{
sturct studenttag student;
char temp[10];
printf(enter student name : );
gets(student.name);
printf(enter student age : );
gets(temp);
student.age = atoi)temp);
printf(enter student grade : );
gets(temp);
student.grade = atoi(temp);
return(student);
}
:
getinfo main
- getinfo
print
** **
. . employee
- employee
- -:
- emp dept
struct employee
{
;]char name[40
;]char address[40
;int age
;float salary
}
struct dept
{
;int deno
;int product
;sturct employee emp
}
dept1
emp
age
** **
#include<stdio.h>
#include<stdlib.h>
struct employee
{
char name[40];
char address[40];
int age;
float salary;
};
struct department
{
int depnum;
char product[40];
struct employee emp;
};
void main(void)
{
struct deparment dept;
char temp[10];
printf(enter dept no : );
gets(temp);
dept.deptnum = atoi(temp);
printf(enter dep. Product : );
gets(dept.product);
prints(enter employee name : );
gets(dept.emp.name);
printf(enter employee address );
gets(dept.emp.address);
printf(enter employee age : );
gets(temp);
dept.emp.age = atoi(temp);
printf(enter employee salary : );
gets(temp);
dept.emp.salary = atof(temp)
printf(\n\n you entered \n\n );
printf(dept no : \t\t%d\n ,dept.deptnum);
printf(dept product : \t\t%s\n ,dept.product);
printf(employee address : \t\t%d\n, dept.emp.address);
-:
- employee
- department employee
gets name
emp :
;)gets(dept.emp.name
printf .
** **
* -:
- : -:
- : -:
struct enployee
{
;]char name[40
;]char address[40
;int age
;float salary
;}
struct employee
{
;]char name[40
;]char address[40
;int age
;float salary
;} emp
emp }
struct employee
{
;]char name[40
;]char address[40
;int age
;float salary
;} emp1 , emp2 , emp3
struct
{
;]char name[40
;]char address[40
;int age
;float salary
;} emp
-:struct
{
;]char name[40
;]char address[40
;int age
;float salary
{ = } emp
ali ahmed
26 st. cairo
39
135.6
;}
pointer
* - : pointer
. ) ( .) (
- .
d 5
- -:
:
.
:
** **
- )
-:
;* p
int
)*(
- p
byte p
;* degree
float
- degress
float
. :struct student
{
;]char name[40
;int mark
}
. :
;struct student *st
** **
&
unary :
;)scanf(%d,&var
;int num
;int *ptr
;num = 5
;ptr = &num
num ptr num
- num 5
num ) ( .
ptr
** ** -:
: .
- .
- :
;)addten(ptr
) * (
; *ptr = 10
- num 10
;a=*ptr* :
>#include<stdio.h
)void main(void
{
;int u = 3
;int v
;int *pu
/* pointer to an integer */
int *pv
/* pointer to an integer */
/* assing address of u to pu */
/* assign values of u to v */
/* assing address of v to pv */
;pu = &u
;v = pu
;pv =&v
u 3 u ) FF8E (
- . pu pu ) ( FF8E
)pu ( FF8E 3
v 3 *pv v** :
>#include<stdio.h
) (main
{
;int u1 ,u2
;int v =3
int pv
/ pv pointer to v */
u1 = 2*(v + 5 ); /* ordinary expression */
; pv = &v
;) u2 = 2*(*pv + 5
printf(\n u1 = %d
;) us2 = %d ,u1 , u2
}
:
- ) 2*(v + 5 .
) 2*(*pv + 5 v , *pv
- :
u2 = 16
pv = 3
)u2 = 2*(*pv + 5
)u2=2*(3+5
u2=16
v=3
u1 = 15
) u1=2*(v + 5
)u1=2*(3+5
u1= 16
** **
C . ) " " ( -:
)void main(void
{
;int num = 5
;)change(num
;
}
5
) : (
* . -:
- :
.
:
-
change :
change(ptr) : ptr
. :
>#include<stdio.d
;) void change( int *ptr
)void main(void
{
;int num = 5
;int *ptr
; ptr = &num
;)printf( berfore change , num =%d \n , num
;)change(ptr
;) printf(after change, num = %d \n , num
}
) void change( int * ptr
{
;*ptr = 7
}
;) void change( int *ptr
- change
ptr = &num
- ptr
change ;*ptr = 7 .
ptr 7
- -:
>#include<stdio.h
;)void fn( int *var1 , int *var2 , int *var3
)void main(void
{
;int var1 ,var2, var3
)fn(&var1 , &var2 , &var3
;)printf(var1 = %d , var2 = %d , var3 = %d, var1 , var2 , var3
}
)void fn( int *p1 , int *p2 , int *p3
{
;*p1=10
;*p2=20
;*p3=30
}
:
var1,var2,var3 - fn
fn p1,p2,p3 - fn
** ** ) (
) (
)
overdue ( delinquent
.
.
* -:
- 10%
overdue
delinquent
* -:
- ) ( .
- -:
2-street
3- city
5- previous balance
6- current balance
1- name
4- account number
7- payment date
-: -
:
1- name
4- city
7- new balance
-
2- account number
3- street
5- old balance
6- current balance
8- account status
-: *
#include<stdio.h>
struct date
{
int month;
int day;
int year;
};
struct account
{
char name[50];
char street[45];
char city[60];
int acc_no;
int acct_type;
/* c = current , o = overdue , d = delinquent */
float oldbalance;
float newbalance;
float paymeny;
struct date lastpayment;
}
main( )
{
int i ,n ;
void readinput(int i );
void writeoutput(int i (;
printf(customer billing system \n\n);
printf(how many customer are there ? );
scanf(%d,&n);
for(i=0,i<n,i++)
{
readinput(i);
if(customer[i].payment > 0 )
customer[i].acct_type =
(customer[i].oldbalance < 0.1*customer[i].oldbalabce) ? o | c;
else
customer[i].acct_type =
(customer[i].oldbalance > 0 ) ? d | c ;
};
for (i = 0 ; i < n ; i ++)
writeoutput(i);
}
void readinput(int i )
{
print(\n customer no. %d\n, i+1);
printf( name : );
sccanf( %[ ] ,customer[ i ].name);
printf( street : ) ;
scanf(% [ ] ,customer[ i ] .street);
printf( city : );
scanf( %[ ] ,customer[ i ] .city );
printf( account number : );
scanf(%d , &customer[ i ] . oldbalance);
printf( current payment : );
scanf(%f, &customer[ i ] .payment);
printf( payment date (mm/dd/yyyy) : );
scanf(%d / %d / %d , &customer[ i ] .lastpayment.month,
&customer[ i ] .lastpayment.day
&customer[ i ] .lastpayment.year
return;
}
void writeoutput(int i)
{
printf( name : %s, customer[i].name);
printf( account number : %d\n, customer[i].acct_no);
printf(street : %s\n , customer[i].street);
printf(city : %s\n\n , customer[i].city);
printf(old balance %7.2f, customer[i].oldbalance);
printf( current payment : %7.2f , customer[i].payment);
printf( new balance : %7.2f\n\ ,customer[i].newblance);
printf( account status : );
switch ( customer[i].acct_type)
{
case c
printf( current\n\n);
break;
case o
;)printf( overdue\n\n
;break
case d
;)printf( delinqunt\n\n
;break
;default
)printf( error \n\n
}
;return
}