LOGO Higher Technological Institute 10th of Ramadan City 6th of October Branch Electrical and Computer Engineering Department Lecture Notes in Prepaid By: Eng. Ibrahim Elewah Main Reference HTI Student Book and “C For Dummies” by Dan Gookin 2nd Edition 1
Course Contents 1 Introduction 2 Program Development 3 The Essential of C Programs 4 Manipulating Data with Operators 5 Reading from and Writing to Standard I/O 6 Decision 7 Iteration 8 Arrays 9 C Functions C Programming 2 Higher Technological Institute
Course Contents 3 The Essential of C Programs  Constants and variables  Expressions  Arithmetic operators  Statements  Statement blocks  Data Types and Names in C  Naming a Variable C Programming 3 Higher Technological Institute
Expressions o An expression is a combination of constants, variables, and operators that are used to denote computations 𝑨= 𝟐∗ 𝑨 − 𝟏 1. Taking the value contained in the drawer (variable) A 2. Multiply this value by 2 3. Subtract 1 from result obtained from 2 4. The value contained in drawer A is omitted, then putting the result obtained from 3 into drawer A. C Programming 4 Higher Technological Institute
Arithmetic Operations Addition Subtraction Multiplication Division Reminder The Reminder operator % is used to obtain the reminder of the first operand divided by the second operand C Programming 5 Higher Technological Institute
Arithmetic Operations Addition Subtraction Multiplication Division Reminder Example 𝟔% 𝟒= 𝟐 C Programming 𝟏𝟎𝟎𝟏%𝟐 = 𝟏 6 𝟒𝟖%𝟓 = Higher Technological Institute
Arithmetic Operations Addition Subtraction Multiplication Division Reminder Example 𝟔% 𝟒= 𝟐 C Programming 𝟏𝟎𝟎𝟏%𝟐 = 𝟏 7 𝟒𝟖%𝟓 = 𝟑 Higher Technological Institute
Constants and Variables o As its name implies, a constant is a value that never changes. o A variable, on the other hand, can be used to present different values. o For instance, consider the following: 𝒊 = 𝟏 ; o Where the symbol i is a constant because it always has the same value (1) and the symbol i is assigned the constant 1. o In other words, i contains the value of 1 after the statement is executed. C Programming 8 Higher Technological Institute
Data Types and Names o The C language reserves some keywords words that have special meanings to the language. o Those reserved words should not be used as variables, constants, or function names in your program. o All C keywords must be written in lowercase letters, for instance INT will not be treated as a keyword, it must be written as int. C Programming 9 Higher Technological Institute
The computer list of C keywords auto const double float int short struct unsigned C Programming break continue else for long signed switch void case default enum goto register sizeof typedef volatile 10 char do extern if return static union while Higher Technological Institute
Naming a Variable Valid Variable Name Can Use o Characters A through Z and a through z o Digit characters 0 through 9, which can be used in any position except the first of a variable name. o The underscore character _ Examples stop_sign C Programming loop3 11 and_pause Higher Technological Institute
Naming a Variable Invalid Variable Name Can NOT be Used o o o o A variable name can’t contain any C arithmetic signs. A variable name can’t contain any dots. A variable name can’t contain any apostrophes. A variable name can’t contain any other special symbols such as *, @, #, and so on. Examples 4flags return C Programming sum-result what_size? 12 method*4 ahmed.ali Higher Technological Institute
Data Types C Data Type char int float double a, B, $, # 5, 17, 128 2.5 , 0.3 23433.3455 C Programming 13 Higher Technological Institute
Declaration Statement Type Name Value char int float double c1 N1 F1 d1 char c1 = ‘&’ ; int ‘&’ 100 32/10 5e3 = 100 ; n1 C Programming 14 Higher Technological Institute
Declaration Statement Type char int float double Name Value ‘&’ 100 32/10 5e3 c1 N1 F1 d1 char c1 ; c1 = ‘&’ ; int ; n1 = 100 ; n1 C Programming 15 Higher Technological Institute
Declaration Statement Type Name Value char int float double float c1 n1 f1 d1 ‘&’ 100 32/10 5e3 f1= 32/100 ; double C Programming d1=5e3 ; 16 Higher Technological Institute
Declaration Statement Type Name Value char int float double ‘&’ 100 32/10 5e3 c1 n1 f1 d1 float f1 ; f1 = 32/100 ; double d1 ; d1 = 5e3 C Programming 17 ; Higher Technological Institute
Some special characters in C b Backspace f Form feed n New line r Return t Tab C Programming Moves the cursor to the left one character Goes to the top of a new page Carriage return and line feeds Returns to the beginning of the current line Advances to the next tab stop 18 Higher Technological Institute
Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ char c2; /* declaration of the character variable c2 */ c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ return 0; } C Programming 19 Higher Technological Institute
Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ char c2; /* declaration of the character variable c2 */ c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 20 Higher Technological Institute
Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 21 Higher Technological Institute
Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 22 Higher Technological Institute
Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 23 Higher Technological Institute
Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } New Line Specifier for Character Data Type C Programming 24 Higher Technological Institute
Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ char c2; /* declaration of the character variable c2 */ c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 25 Higher Technological Institute
You Have To Know about Data Types Type Name Value Specifier char c1 ‘&’ %c int n1 100 %d float f1 32/10 %f double d1 5e3 %e,%E C Programming 26 Higher Technological Institute
Examples /* The arithmetic operations on integers */ # include<stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 15 */ int m = 3; int n=2; printf ( "The summation of %d and %d is : %d.n", m, n, m+n); printf ( "The difference between %d and %d is : %d.n", m, n, m-n); printf ( "The multiplication of %d by %d is : %d.n", m, n, m*n); printf ( "The division of %d by %d is : %d.n", m, n, m/n); printf ( "The remainder of division of %d by %d is : %d.n", m, n, m%n); return 0 ; } C Programming 27 Higher Technological Institute
Operators Precedence Operator Sign ( ) / * + - C Programming Name Brackets Division Multiplication Addition Subtraction 28 Higher Technological Institute
Logic Operators Operator Sign || && != C Programming Name OR AND NOT 29 Higher Technological Institute
Examples /* Example3 : Integer vs. floating point divisions */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { int n1,n2,n3; float m1,m2,m3; n1 = 32/10; m1= 32/10; n2 = 32.0/10; m2= 32.0/10; n3 = 32/10.0; m3 = 32/10.0; return 0; } C Programming 30 Higher Technological Institute
Examples /* Example3 : Integer vs. floating point divisions */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { int n1,n2,n3; float m1,m2,m3; n1 = 32/10; m1= 32/10; n2 = 32.0/10; m2= 32.0/10; n3 = 32/10.0; m3 = 32/10.0; printf ( “ The integer division of 32/10 is : %d n”, n1); printf ( “The floating point division of 32/10 is : %f n”, m1); printf ( “The integer division of 32.0/10 is : %d n”, n2); printf ( “The floating point division of 32.0/10 is : %f n”, m2); printf ( “The integer division of 32/10.0 is : %d n”, n3); printf ( “The floating point division of 32/10.0 is : %f n”, m3); return 0; } C Programming 31 Higher Technological Institute
Double Data Type o Here are two examples: [mantissa] e [exponent] [mantissa] E [exponent] Example 5000 -300 0.0025 5e3. -3e2 2.5e-3. Specifier %e or %E With printf ( ) C Programming 32 Higher Technological Institute
Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 33 Higher Technological Institute
Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 34 Higher Technological Institute
Precedence Example # include<stdio.h> X( B/C + A ; main = ) E * D – { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 35 Higher Technological Institute
Precedence Example X= E*D – X= E*D – C Programming B/C B/C + A ; + A ; 36 Higher Technological Institute
Precedence Example X= E*D – C Programming B/C + A ; 37 Higher Technological Institute
Precedence Example X= E*D – B/C + A ; A = 20 B=6 C=3 D = 10 E=2 C Programming ( ) * / +- 38 Higher Technological Institute
Precedence Example X= E*D – 2 * 10 – A = 20 B/C + A ; 6 / 3 + 20 B=6 C=3 D = 10 E=2 C Programming 39 ( ) * / +- Higher Technological Institute
Precedence Example X= E*D – 2 * 10 – A = 20 B=6 C=3 D = 10 E=2 C Programming 20 B/C + A ; 6 / 3 + 20 – 2 40 + 20 ( ) * / +- Higher Technological Institute
Precedence Example X= E*D – 2 * 10 – A = 20 B=6 C=3 D = 10 E=2 C Programming 20 B/C + A ; 6 / 3 + 20 – 2 38 41 + 20 ( ) * / +- Higher Technological Institute
Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 42 Higher Technological Institute
Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 43 Higher Technological Institute
Precedence Example # include<stdio.h> main = )( E * D ) – ( B / C ) + A ; Y ( { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 44 Higher Technological Institute
Precedence Example Y=(E*D)–(B/C)+ A ; . . . C Programming 45 Higher Technological Institute
Precedence Example Y=(E*D)–(B/C)+ A ; . . . 38 C Programming 46 Higher Technological Institute
Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 47 Higher Technological Institute
Precedence Example # include<stdio.h> Z( = A * ( D – B ) / ( C + E ) ; main ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 48 Higher Technological Institute
Precedence Example Z= A*(D–B)/(C+ E); A = 20 B=6 C=3 D = 10 E=2 C Programming ( ) * / +- 49 Higher Technological Institute
Precedence Example Z= A*(D–B)/(C+ E); A = 20 B=6 C=3 D = 10 E=2 C Programming ( ) * / +- 50 Higher Technological Institute
Precedence Example Z= A*(D–B)/(C+ E); A = 20 B=6 C=3 D = 10 E=2 C Programming 20 * 4 / 51 5 ( ) * / +- Higher Technological Institute
Precedence Example Z= A*(D–B)/(C+ E); A = 20 B=6 C=3 D = 10 E=2 C Programming 20 * 4 / 16 52 5 ( ) * / +- Higher Technological Institute
Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 53 Higher Technological Institute
Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 54 Higher Technological Institute
Home Work ..!! Exercises 3 Page 44 C Programming 55 Higher Technological Institute
LOGO Higher Technological Institute 10th of Ramadan City 6th of October Branch Electrical and Computer Engineering Department Eng. Ibrahim Elewah Main Reference HTI Student Book and “C For Dummies” by Dan Gookin 2nd Edition 56

Computer programming chapter ( 3 )

  • 1.
    LOGO Higher Technological Institute 10thof Ramadan City 6th of October Branch Electrical and Computer Engineering Department Lecture Notes in Prepaid By: Eng. Ibrahim Elewah Main Reference HTI Student Book and “C For Dummies” by Dan Gookin 2nd Edition 1
  • 2.
    Course Contents 1 Introduction 2 Program Development 3 TheEssential of C Programs 4 Manipulating Data with Operators 5 Reading from and Writing to Standard I/O 6 Decision 7 Iteration 8 Arrays 9 C Functions C Programming 2 Higher Technological Institute
  • 3.
    Course Contents 3 The Essentialof C Programs  Constants and variables  Expressions  Arithmetic operators  Statements  Statement blocks  Data Types and Names in C  Naming a Variable C Programming 3 Higher Technological Institute
  • 4.
    Expressions o An expressionis a combination of constants, variables, and operators that are used to denote computations 𝑨= 𝟐∗ 𝑨 − 𝟏 1. Taking the value contained in the drawer (variable) A 2. Multiply this value by 2 3. Subtract 1 from result obtained from 2 4. The value contained in drawer A is omitted, then putting the result obtained from 3 into drawer A. C Programming 4 Higher Technological Institute
  • 5.
    Arithmetic Operations Addition Subtraction Multiplication Division Reminder The Reminderoperator % is used to obtain the reminder of the first operand divided by the second operand C Programming 5 Higher Technological Institute
  • 6.
    Arithmetic Operations Addition Subtraction Multiplication Division Reminder Example 𝟔% 𝟒=𝟐 C Programming 𝟏𝟎𝟎𝟏%𝟐 = 𝟏 6 𝟒𝟖%𝟓 = Higher Technological Institute
  • 7.
    Arithmetic Operations Addition Subtraction Multiplication Division Reminder Example 𝟔% 𝟒=𝟐 C Programming 𝟏𝟎𝟎𝟏%𝟐 = 𝟏 7 𝟒𝟖%𝟓 = 𝟑 Higher Technological Institute
  • 8.
    Constants and Variables oAs its name implies, a constant is a value that never changes. o A variable, on the other hand, can be used to present different values. o For instance, consider the following: 𝒊 = 𝟏 ; o Where the symbol i is a constant because it always has the same value (1) and the symbol i is assigned the constant 1. o In other words, i contains the value of 1 after the statement is executed. C Programming 8 Higher Technological Institute
  • 9.
    Data Types andNames o The C language reserves some keywords words that have special meanings to the language. o Those reserved words should not be used as variables, constants, or function names in your program. o All C keywords must be written in lowercase letters, for instance INT will not be treated as a keyword, it must be written as int. C Programming 9 Higher Technological Institute
  • 10.
    The computer listof C keywords auto const double float int short struct unsigned C Programming break continue else for long signed switch void case default enum goto register sizeof typedef volatile 10 char do extern if return static union while Higher Technological Institute
  • 11.
    Naming a Variable ValidVariable Name Can Use o Characters A through Z and a through z o Digit characters 0 through 9, which can be used in any position except the first of a variable name. o The underscore character _ Examples stop_sign C Programming loop3 11 and_pause Higher Technological Institute
  • 12.
    Naming a Variable InvalidVariable Name Can NOT be Used o o o o A variable name can’t contain any C arithmetic signs. A variable name can’t contain any dots. A variable name can’t contain any apostrophes. A variable name can’t contain any other special symbols such as *, @, #, and so on. Examples 4flags return C Programming sum-result what_size? 12 method*4 ahmed.ali Higher Technological Institute
  • 13.
    Data Types C DataType char int float double a, B, $, # 5, 17, 128 2.5 , 0.3 23433.3455 C Programming 13 Higher Technological Institute
  • 14.
    Declaration Statement Type Name Value char int float double c1 N1 F1 d1 charc1 = ‘&’ ; int ‘&’ 100 32/10 5e3 = 100 ; n1 C Programming 14 Higher Technological Institute
  • 15.
    Declaration Statement Type char int float double Name Value ‘&’ 100 32/10 5e3 c1 N1 F1 d1 charc1 ; c1 = ‘&’ ; int ; n1 = 100 ; n1 C Programming 15 Higher Technological Institute
  • 16.
    Declaration Statement Type Name Value char int float double float c1 n1 f1 d1 ‘&’ 100 32/10 5e3 f1=32/100 ; double C Programming d1=5e3 ; 16 Higher Technological Institute
  • 17.
  • 18.
    Some special charactersin C b Backspace f Form feed n New line r Return t Tab C Programming Moves the cursor to the left one character Goes to the top of a new page Carriage return and line feeds Returns to the beginning of the current line Advances to the next tab stop 18 Higher Technological Institute
  • 19.
    Examples /* Example1 :Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ char c2; /* declaration of the character variable c2 */ c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ return 0; } C Programming 19 Higher Technological Institute
  • 20.
    Examples /* Example1 :Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ char c2; /* declaration of the character variable c2 */ c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 20 Higher Technological Institute
  • 21.
    Examples /* Example1 :Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 21 Higher Technological Institute
  • 22.
    Examples /* Example1 :Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 22 Higher Technological Institute
  • 23.
    Examples /* Example1 :Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 23 Higher Technological Institute
  • 24.
    Examples /* Example1 :Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } New Line Specifier for Character Data Type C Programming 24 Higher Technological Institute
  • 25.
    Examples /* Example1 :Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ char c2; /* declaration of the character variable c2 */ c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 25 Higher Technological Institute
  • 26.
    You Have ToKnow about Data Types Type Name Value Specifier char c1 ‘&’ %c int n1 100 %d float f1 32/10 %f double d1 5e3 %e,%E C Programming 26 Higher Technological Institute
  • 27.
    Examples /* The arithmeticoperations on integers */ # include<stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 15 */ int m = 3; int n=2; printf ( "The summation of %d and %d is : %d.n", m, n, m+n); printf ( "The difference between %d and %d is : %d.n", m, n, m-n); printf ( "The multiplication of %d by %d is : %d.n", m, n, m*n); printf ( "The division of %d by %d is : %d.n", m, n, m/n); printf ( "The remainder of division of %d by %d is : %d.n", m, n, m%n); return 0 ; } C Programming 27 Higher Technological Institute
  • 28.
    Operators Precedence Operator Sign () / * + - C Programming Name Brackets Division Multiplication Addition Subtraction 28 Higher Technological Institute
  • 29.
    Logic Operators Operator Sign || && != CProgramming Name OR AND NOT 29 Higher Technological Institute
  • 30.
    Examples /* Example3 :Integer vs. floating point divisions */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { int n1,n2,n3; float m1,m2,m3; n1 = 32/10; m1= 32/10; n2 = 32.0/10; m2= 32.0/10; n3 = 32/10.0; m3 = 32/10.0; return 0; } C Programming 30 Higher Technological Institute
  • 31.
    Examples /* Example3 :Integer vs. floating point divisions */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { int n1,n2,n3; float m1,m2,m3; n1 = 32/10; m1= 32/10; n2 = 32.0/10; m2= 32.0/10; n3 = 32/10.0; m3 = 32/10.0; printf ( “ The integer division of 32/10 is : %d n”, n1); printf ( “The floating point division of 32/10 is : %f n”, m1); printf ( “The integer division of 32.0/10 is : %d n”, n2); printf ( “The floating point division of 32.0/10 is : %f n”, m2); printf ( “The integer division of 32/10.0 is : %d n”, n3); printf ( “The floating point division of 32/10.0 is : %f n”, m3); return 0; } C Programming 31 Higher Technological Institute
  • 32.
    Double Data Type oHere are two examples: [mantissa] e [exponent] [mantissa] E [exponent] Example 5000 -300 0.0025 5e3. -3e2 2.5e-3. Specifier %e or %E With printf ( ) C Programming 32 Higher Technological Institute
  • 33.
    Precedence Example # include<stdio.h> main( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 33 Higher Technological Institute
  • 34.
    Precedence Example # include<stdio.h> main( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 34 Higher Technological Institute
  • 35.
    Precedence Example # include<stdio.h> X( B/C+ A ; main = ) E * D – { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 35 Higher Technological Institute
  • 36.
    Precedence Example X= E*D– X= E*D – C Programming B/C B/C + A ; + A ; 36 Higher Technological Institute
  • 37.
    Precedence Example X= E*D– C Programming B/C + A ; 37 Higher Technological Institute
  • 38.
    Precedence Example X= E*D– B/C + A ; A = 20 B=6 C=3 D = 10 E=2 C Programming ( ) * / +- 38 Higher Technological Institute
  • 39.
    Precedence Example X= E*D– 2 * 10 – A = 20 B/C + A ; 6 / 3 + 20 B=6 C=3 D = 10 E=2 C Programming 39 ( ) * / +- Higher Technological Institute
  • 40.
    Precedence Example X= E*D– 2 * 10 – A = 20 B=6 C=3 D = 10 E=2 C Programming 20 B/C + A ; 6 / 3 + 20 – 2 40 + 20 ( ) * / +- Higher Technological Institute
  • 41.
    Precedence Example X= E*D– 2 * 10 – A = 20 B=6 C=3 D = 10 E=2 C Programming 20 B/C + A ; 6 / 3 + 20 – 2 38 41 + 20 ( ) * / +- Higher Technological Institute
  • 42.
    Precedence Example # include<stdio.h> main( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 42 Higher Technological Institute
  • 43.
    Precedence Example # include<stdio.h> main( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 43 Higher Technological Institute
  • 44.
    Precedence Example # include<stdio.h> main= )( E * D ) – ( B / C ) + A ; Y ( { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 44 Higher Technological Institute
  • 45.
    Precedence Example Y=(E*D)–(B/C)+ A; . . . C Programming 45 Higher Technological Institute
  • 46.
    Precedence Example Y=(E*D)–(B/C)+ A; . . . 38 C Programming 46 Higher Technological Institute
  • 47.
    Precedence Example # include<stdio.h> main( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 47 Higher Technological Institute
  • 48.
    Precedence Example # include<stdio.h> Z(= A * ( D – B ) / ( C + E ) ; main ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 48 Higher Technological Institute
  • 49.
    Precedence Example Z= A*(D–B)/(C+E); A = 20 B=6 C=3 D = 10 E=2 C Programming ( ) * / +- 49 Higher Technological Institute
  • 50.
    Precedence Example Z= A*(D–B)/(C+E); A = 20 B=6 C=3 D = 10 E=2 C Programming ( ) * / +- 50 Higher Technological Institute
  • 51.
    Precedence Example Z= A*(D–B)/(C+E); A = 20 B=6 C=3 D = 10 E=2 C Programming 20 * 4 / 51 5 ( ) * / +- Higher Technological Institute
  • 52.
    Precedence Example Z= A*(D–B)/(C+E); A = 20 B=6 C=3 D = 10 E=2 C Programming 20 * 4 / 16 52 5 ( ) * / +- Higher Technological Institute
  • 53.
    Precedence Example # include<stdio.h> main( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 53 Higher Technological Institute
  • 54.
    Precedence Example # include<stdio.h> main( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 54 Higher Technological Institute
  • 55.
    Home Work ..!! Exercises3 Page 44 C Programming 55 Higher Technological Institute
  • 56.
    LOGO Higher Technological Institute 10thof Ramadan City 6th of October Branch Electrical and Computer Engineering Department Eng. Ibrahim Elewah Main Reference HTI Student Book and “C For Dummies” by Dan Gookin 2nd Edition 56