intro to c chapter cover 1 4
DESCRIPTION
TRANSCRIPT
![Page 1: Intro to c chapter cover 1 4](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/1.jpg)
Created by: Arave
![Page 2: Intro to c chapter cover 1 4](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/2.jpg)
Flowchart
![Page 3: Intro to c chapter cover 1 4](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/4.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/5.jpg)
C Structure
Preprocessor Directives
Global Declaration
void main(){
}
Local Declaration
Statements
![Page 6: Intro to c chapter cover 1 4](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/8.jpg)
Example
#include <stdio.h>#include <stlib.h>
void main(){
printf("Hello world!!!");
}
Header files
![Page 9: Intro to c chapter cover 1 4](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/9.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/10.jpg)
Example
void main(){ int num1; printf(“Key-in number: "); //Input scanf(“%d”,&num1);
.
.
.
.
.
. return 0;}
![Page 11: Intro to c chapter cover 1 4](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/11.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/12.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/13.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/14.jpg)
%sstring
%ldlong int
%lfdouble
%cchar
%ffloat
%d, %iint
scanf Format Specifier
Variable type
![Page 15: Intro to c chapter cover 1 4](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/15.jpg)
Type of arithmetic operator
Substraction-
Addition+
Modulus%
Division and integer division/
Multiplication*
MeaningType
![Page 16: Intro to c chapter cover 1 4](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/16.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/17.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/18.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/19.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022081602/5461ddebaf7959ba618b4a13/html5/thumbnails/20.jpg)
Thank You!