50 likes | 59 Views
Discover the advantages of programming with C, a powerful and flexible language. Learn how to edit, compile, and run source code, and explore control structures, input/output, operators, and format specifications.
E N D
Programming with C Sung-Ju Kang Department Of Physics Kangwon National University 1. Advantage of C Language • Powerful and flexible language • Operation plenty • Portable language • Language of low level special quality. 2. Programming with C • Edit and save the source code using the editor (ASCII). $ tc • Compiled the source code. $ tcc filename.c Make an object code. • Run it. $ filename.exe
3. Generic Program Written by C Main function is main body of program written by c. A sentence is finished the semicolon (;). Subroutines is started ({) and is finished (}). Comments : /* . . . */ or // • Include header files #include <filename.h> #include “filename.h” • Variables declaration Global variables Local variables • Subroutines Return the value Void type • Print the output on the screen
4. Control Structures in C -Distinguisher • if statements : If “conditions” is TRUE, then run “statements”. If “conditions” is FALSE, then run “statements2”. -Repetition • while statements : Run “statements” while “conditions” is TRUE. can change “conditions”. • for statements : i starts at 1, and run “statements” until i is imax. • do . . . while statements : Run “statements” while “conditions” is a TRUE.
5. Input and Output in C Input and output to screen Input and output to files
6. Operators and Format Specifies and Escape sequences in C. Relational operators == : equal != : not equal Logical operators && : AND || : OR ! : NOT Format of output specifies %c : char %s : char* %d : int, short %ld : long %f : float %lf : long double %e : float (form of index) Type cast operators ++ : increase 1 -- : decrease 1 Escape sequences \a : bell, beep \b : backspace \n : new line \t : tap \\ : back slash \‘ : ‘ (quotation mark)