intro to c chapter cover 1 4

Post on 11-Nov-2014

331 Views

Category:

Education

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Created by: Arave

Flowchart

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

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;}

C Structure

Preprocessor Directives

Global Declaration

void main(){

}

Local Declaration

Statements

Preprocessor Directives

First statement executed by compiler

Begin with a pound sign or hash ( # )

Example : #include and #define

Header Files/Libraries

Header files have the extension .h

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

Example

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

void main(){

printf("Hello world!!!");

}

Header files

Input (printf)

How to transfer/store the data to computer

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

User understand type of input data

Example

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

.

.

.

.

.

. return 0;}

Single quote\’

double quote\”

backslash\\

Bell or a beep\a

backspace\b

Vertical tab\v

Horizontal tab\t

New line\n

functionsEscape sequence

Input (scanf)

Address in which user input store temporary

Symbol ‘&’ referred to address to the variable

Example

void main(){ int num1; //variable

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

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

return 0;}

%sstring

%ldlong int

%lfdouble

%cchar

%ffloat

%d, %iint

scanf Format Specifier

Variable type

Type of arithmetic operator

Substraction-

Addition+

Modulus%

Division and integer division/

Multiplication*

MeaningType

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

Order of precedence

• Arithmetic Operation Priority

High Priority

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

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

Type of Logical Operator

NOT

OR

ANDMeaning

!(x>=y)

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

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

Example

!

||

&&Operator

Thank You!

top related