20
Created by: Arave

Intro to c chapter cover 1 4

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Intro to c chapter cover 1 4

Created by: Arave

Page 2: Intro to c chapter cover 1 4

Flowchart

Page 3: Intro to c chapter cover 1 4

Example flowchartProblem: Add 2 numbersPseudo code

1. Begin

2. Read number 1

3. Read number 2

4. Add number 1 & number 2

5. End

Begin

Read number 1

Read number 2

Answer = no1 + no2

End

Page 4: Intro to c chapter cover 1 4

Example C Programming#include <stdio.h> //Preprocessor Directives

int main (){//Local Declaration int a, b, sum;

//Statements printf("Enter two numbers\n: "); scanf("%d %d", &a, &b);

//Operation sum = a + b;

//Output printf("The total is:%d", sum);

getch (); return 0;}

Page 5: Intro to c chapter cover 1 4

C Structure

Preprocessor Directives

Global Declaration

void main(){

}

Local Declaration

Statements

Page 6: Intro to c chapter cover 1 4

Preprocessor Directives

First statement executed by compiler

Begin with a pound sign or hash ( # )

Example : #include and #define

Page 7: Intro to c chapter cover 1 4

Header Files/Libraries

Header files have the extension .h

two ways to include a header file:1. #include "stdio.h" 2. #include <stdio.h>

Page 8: Intro to c chapter cover 1 4

Example

#include <stdio.h>#include <stlib.h>

void main(){

printf("Hello world!!!");

}

Header files

Page 9: Intro to c chapter cover 1 4

Input (printf)

How to transfer/store the data to computer

Interactive – keyboard, touch screen, mouse – response from user

User understand type of input data

Page 10: Intro to c chapter cover 1 4

Example

void main(){ int num1; printf(“Key-in number: "); //Input scanf(“%d”,&num1);

.

.

.

.

.

. return 0;}

Page 11: Intro to c chapter cover 1 4

Single quote\’

double quote\”

backslash\\

Bell or a beep\a

backspace\b

Vertical tab\v

Horizontal tab\t

New line\n

functionsEscape sequence

Page 12: Intro to c chapter cover 1 4

Input (scanf)

Address in which user input store temporary

Symbol ‘&’ referred to address to the variable

Page 13: Intro to c chapter cover 1 4

Example

void main(){ int num1; //variable

printf(“Key-in number: "); //Input

scanf(“%d”,&num1); ......

return 0;}

Page 14: Intro to c chapter cover 1 4

%sstring

%ldlong int

%lfdouble

%cchar

%ffloat

%d, %iint

scanf Format Specifier

Variable type

Page 15: Intro to c chapter cover 1 4

Type of arithmetic operator

Substraction-

Addition+

Modulus%

Division and integer division/

Multiplication*

MeaningType

Page 16: Intro to c chapter cover 1 4

Unary Operator

i-=1;i=i-1;Prefix--i;--

i+=1;i=i+1;Prefix++i;++i-=1;i=i-1;Postfixi--;--

i+=1;i=i+1;Postfixi++;++Statements

EquivalentDescriptionExampleOperator

Page 17: Intro to c chapter cover 1 4

Order of precedence

• Arithmetic Operation Priority

High Priority

( ) left to right++, -- left to right* , /, % left to right+ , - left to right

Page 18: Intro to c chapter cover 1 4

Type of Relational Operator

x!=y

x<=y

x>=y

x<y

x>y

x==y

Example

Not equal to!=

less or equal<=

greater or equal

>=

less than<

greater than>

equal to==

DescriptionOperator

Page 19: Intro to c chapter cover 1 4

Type of Logical Operator

NOT

OR

ANDMeaning

!(x>=y)

((x<y)||(x!=0))

((x<y)&&(x!=0))

Example

!

||

&&Operator

Page 20: Intro to c chapter cover 1 4

Thank You!