Download presentation
Presentation is loading. Please wait.
Published byBailey Scarbrough Modified over 9 years ago
1
C-Language : Basic Concepts 2013, Fall Pusan National University Ki-Joune Li
2
Basic Concepts Plan Computer Programming Languages and C- Language Programming Procedure A Sample Program Programming Assignment - 1
3
C-Language: A Computer Programming Language Program Communication between human and computer Program: A sequence of instructions to a computer Programming Language: Syntax and Grammar of Program Cf. Natural Language ComputerProgrammer Instructions Sequence of Instructions: Computer Program
4
C-Language: A Computer Programming Language C-Language Developed in 1970s Initially designed and developed for UNIX Becomes a most popular computer programming language In comparison with other languages Relatively close to machine language Easy to handle hardware and systems Computer Engineer: Should be a native speaker of C-Language
5
Programming Procedure Step 1: Design Design Structures and Algorithms of the program Step 2: Editing and Coding Editing a program With an editing or programming environment Ex. Vi, emacs in Unix, MS visual studio, etc.. Step 3: Compile Translation of a program to (executable) machine code Compiler Step 4: Execute and Debug
6
Programming Procedure Example Design Visual C/C++ EditingCompile MS-Windows Sample.c Execution Sample.obj Sample.exe Results
7
A Sample Program #include main() { float a,b,c; /* ax 2 + bx + c=0 */ float x1,x2; double D; /* input coefficients */ printf( “ Input a b c : ” ); scanf( “ %f %f %f ”, &a, &b, &c); if(a==0) { if(b==0) { if(c==0) printf( “ Any real number\n ” ); else printf( “ No Solution\n ” ); } else { /* b!=0 */ x1= -c/a; printf( “ Solution x=%f\n ”, x1); } else { /* a!=0 */ D = doubleb*b-4.0*a*c; if(D<0) printf( “ No Solution\n ” ); else if(D==0) { x1=-b/(2.0*a); printf( “ Solution x=%f\n ”, x1); } else { x1=(-b+sqrt(D))/(2.0*a); x2=(-b-sqrt(D))/(2.0*a); printf(Solution x1=%f x2=%f\n ”,x1,x2); } Block
8
3. Sample Program #include main() { float a,b,c; /* ax 2 + bx + c=0 */ float x1,x2; double D; /* input coefficients */ printf( “ Input a b c : ” ); scanf( “ %f %f %f ”, &a, &b, &c); if(a==0) { if(b==0) { if(c==0) printf( “ Any real number\n ” ); else printf( “ No Solution\n ” ); } else { /* b!=0 */ x1= -c/a; printf( “ Solution x=%f\n ”, x1); } else { /* a!=0 */ D = doubleb*b-4.0*a*c; if(D<0) printf( “ No Solution\n ” ); else if(D==0) { x1=-b/(2.0*a); printf( “ Solution x=%f\n ”, x1); } else { x1=(-b+sqrt(D))/(2.0*a); x2=(-b-sqrt(D))/(2.0*a); printf(Solution x1=%f x2=%f\n ”,x1,x2); } Variable Value
9
3. Sample Program #include main() { float a,b,c; /* ax 2 + bx + c=0 */ float x1,x2; double D; /* input coefficients */ printf( “ Input a b c : ” ); scanf( “ %f %f %f ”, &a, &b, &c); if(a==0) { if(b==0) { if(c==0) printf( “ Any real number\n ” ); else printf( “ No Solution\n ” ); } else { /* b!=0 */ x1= -c/a; printf( “ Solution x=%f\n ”, x1); } else { /* a!=0 */ D = doubleb*b-4.0*a*c; if(D<0) printf( “ No Solution\n ” ); else if(D==0) { x1=-b/(2.0*a); printf( “ Solution x=%f\n ”, x1); } else { x1=(-b+sqrt(D))/(2.0*a); x2=(-b-sqrt(D))/(2.0*a); printf(Solution x1=%f x2=%f\n ”,x1,x2); } Type Declaration
10
3. Sample Program #include main() { float a,b,c; /* ax 2 + bx + c=0 */ float x1,x2; double D; /* input coefficients */ printf( “ Input a b c : ” ); scanf( “ %f %f %f ”, &a, &b, &c); if(a==0) { if(b==0) { if(c==0) printf( “ Any real number\n ” ); else printf( “ No Solution\n ” ); } else { /* b!=0 */ x1= -c/a; printf( “ Solution x=%f\n ”, x1); } else { /* a!=0 */ D = doubleb*b-4.0*a*c; if(D<0) printf( “ No Solution\n ” ); else if(D==0) { x1=-b/(2.0*a); printf( “ Solution x=%f\n ”, x1); } else { x1=(-b+sqrt(D))/(2.0*a); x2=(-b-sqrt(D))/(2.0*a); printf(Solution x1=%f x2=%f\n ”,x1,x2); } Statement
11
3. Sample Program #include main() { float a,b,c; /* ax 2 + bx + c=0 */ float x1,x2; double D; /* input coefficients */ printf( “ Input a b c : ” ); scanf( “ %f %f %f ”, &a, &b, &c); if(a==0) { if(b==0) { if(c==0) printf( “ Any real number\n ” ); else printf( “ No Solution\n ” ); } else { /* b!=0 */ x1= -c/a; printf( “ Solution x=%f\n ”, x1); } else { /* a!=0 */ D = doubleb*b-4.0*a*c; if(D<0) printf( “ No Solution\n ” ); else if(D==0) { x1=-b/(2.0*a); printf( “ Solution x=%f\n ”, x1); } else { x1=(-b+sqrt(D))/(2.0*a); x2=(-b-sqrt(D))/(2.0*a); printf(Solution x1=%f x2=%f\n ”,x1,x2); } Control Flow
12
3. Sample Program #include main() { float a,b,c; /* ax 2 + bx + c=0 */ float x1,x2; double D; /* input coefficients */ printf( “ Input a b c : ” ); scanf( “ %f %f %f ”, &a, &b, &c); if(a==0) { if(b==0) { if(c==0) printf( “ Any real number\n ” ); else printf( “ No Solution\n ” ); } else { /* b!=0 */ x1= -c/a; printf( “ Solution x=%f\n ”, x1); } else { /* a!=0 */ D = doubleb*b-4.0*a*c; if(D<0) printf( “ No Solution\n ” ); else if(D==0) { x1=-b/(2.0*a); printf( “ Solution x=%f\n ”, x1); } else { x1=(-b+sqrt(D))/(2.0*a); x2=(-b-sqrt(D))/(2.0*a); printf(Solution x1=%f x2=%f\n ”,x1,x2); } Condition
13
3. Sample Program #include main() { float a,b,c; /* ax 2 + bx + c=0 */ float x1,x2; double D; /* input coefficients */ printf( “ Input a b c : ” ); scanf( “ %f %f %f ”, &a, &b, &c); if(a==0) { if(b==0) { if(c==0) printf( “ Any real number\n ” ); else printf( “ No Solution\n ” ); } else { /* b!=0 */ x1= -c/a; printf( “ Solution x=%f\n ”, x1); } else { /* a!=0 */ D = doubleb*b-4.0*a*c; if(D<0) printf( “ No Solution\n ” ); else if(D==0) { x1=-b/(2.0*a); printf( “ Solution x=%f\n ”, x1); } else { x1=(-b+sqrt(D))/(2.0*a); x2=(-b-sqrt(D))/(2.0*a); printf(Solution x1=%f x2=%f\n ”,x1,x2); } Assignment
14
3. Sample Program #include main() { float a,b,c; /* ax 2 + bx + c=0 */ float x1,x2; double D; /* input coefficients */ printf( “ Input a b c : ” ); scanf( “ %f %f %f ”, &a, &b, &c); if(a==0) { if(b==0) { if(c==0) printf( “ Any real number\n ” ); else printf( “ No Solution\n ” ); } else { /* b!=0 */ x1= -c/a; printf( “ Solution x=%f\n ”, x1); } else { /* a!=0 */ D = doubleb*b-4.0*a*c; if(D<0) printf( “ No Solution\n ” ); else if(D==0) { x1=-b/(2.0*a); printf( “ Solution x=%f\n ”, x1); } else { x1=(-b+sqrt(D))/(2.0*a); x2=(-b-sqrt(D))/(2.0*a); printf(Solution x1=%f x2=%f\n ”,x1,x2); } Operator Operator precedence : ( ) > *, / > …
15
3. Sample Program #include main() { float a,b,c; /* ax 2 + bx + c=0 */ float x1,x2; double D; /* input coefficients */ printf( “ Input a b c : ” ); scanf( “ %f %f %f ”, &a, &b, &c); if(a==0) { if(b==0) { if(c==0) printf( “ Any real number\n ” ); else printf( “ No Solution\n ” ); } else { /* b!=0 */ x1= -c/a; printf( “ Solution x=%f\n ”, x1); } else { /* a!=0 */ D = doubleb*b-4.0*a*c; if(D<0) printf( “ No Solution\n ” ); else if(D==0) { x1=-b/(2.0*a); printf( “ Solution x=%f\n ”, x1); } else { x1=(-b+sqrt(D))/(2.0*a); x2=(-b-sqrt(D))/(2.0*a); printf(Solution x1=%f x2=%f\n ”,x1,x2); } Input/Output
16
Basic Concepts of Sample Program Block : { … } Value, Variable Type Declaration : integer, float, double, etc. Statement and Semi-colon (“;”) Control Flow : if.. else if … else Condition Assignment (“=“) Operator, Operator Precedence Function Input and Output with printf and scanf
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.