SlideServe
Menu
Préférences
© SlideServe · v2026

C Programming

khuong avatar
16 diapositives · 500 Views · Aug 14, 2014

C Programming. Chapter – 1 Introduction. Study Book for one month – 25% Learning rate Use Compiler for one month – 60%. Environmental Setup . Install Microsoft Visual studio (Compiler) OR Code::Blocks with MinGW (http://www.cprogramming.com/code_blocks/)

C Programming - slide 1
01 / 16C Programming
1 / 17

Télécharger la présentation

C Programming
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. C Programming

  2. Chapter – 1 Introduction

  3. Study Book for one month – 25% Learning rate • Use Compiler for one month – 60%

  4. Environmental Setup • Install Microsoft Visual studio (Compiler) OR Code::Blocks with MinGW (http://www.cprogramming.com/code_blocks/) • Download Book – The C Programming Language – Brian W. Kernighan, Dennis M. Ritchie (Open source)

  5. C Program Structure • A C program basically consists of the following parts: • Preprocessor Commands • Functions • Variables • Statements & Expressions • Comments

  6. 1. The first line of the program #include <stdio.h> is a preprocessor command. • It tells the compiler to include the standard I/O lirary. • 2. The next line int main() is the main function where program execution begins. In this case function without any argument values. • Many cases – Main(int a, int b) – passing some arguments • 3. The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.

  7. 4. The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen. "Hello, World!" – argument Data type – string \n – is also string, but its newline character. • 5. The next line return 0; terminates main()function and returns the value 0. • “;” - semicolon is must for every statement. • Try exercise 1-1, 1-2

  8. Data types • In the C programming language, data types refer to an extensive system used for declaring variables or functions of different types. • The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. • Size of the objects are usually machine dependent. • Integer types

  9. Floating point types

  10. To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes. • %E – exponential form • Limits.h - ? • Float.h - ? • Cstdio – std::getchar(); any guess? • In c(gcc compiler) – stdio.h– getchar(); • In c++(msvcom compiler) – cstdio – std::getchar(); • Be aware of which compiler you are using and some function may vary. • There also Arrays, structures, void, unions etc.. (save your for time for another day!) Reference: http://www.cplusplus.com/reference/cfloat/

  11. Variables & Arithmetic Expressions Reference: Kernighan, Brian W. The C programming language

  12. All variables – declared before using it. • Usually it starts with the type name (intfahr, celsius) • Followed by the whitespace and then some name. • Assignment of values and initialize. • While(……) is called condition in parentheses • If the condition satisfies then it flows to the next line, if not it is terminated.

  13. Tip: A Menu, Server • While(1){ ……. } - any guess? • The reason for multiplying by 5 and then dividing by 9 instead of multiplying by 5/9 is because integer division truncates any fractional part. In this case the answer will be zero. • In printf %d, \t are used – decimal and tab space. • Try different for example - %s, %c, %f, %o, %X,... • % is always paired with some arguments and awaits another argument, instead of a decimal when a floating point is given it gives wrong answer. • Question – what datatype for fahr and Celsius? • 5.0/9.0 is not truncated.

  14. Symbolic Constants • Always the name is written in Uppercase (Good programming practice) • Replacement text can be anything • Sequence of characters • Numbers • No need for semicolon at the end of the define.

  15. The For loop statement • Most of the variables are eliminated. • Its more compact than the while statement • Inside the parentheses three parts separated with semicolon, first is • Fahr = 0 (initialize) • Fahr<= 300 (controlling part) • Fahr = fahr+20 (increment step) • The loop terminates if the condition is false.

  16. Write a C program to convert Celsius to Fahrenheit between 0 to 200 with a step size of 20 and print the value in reverse order. You can use any loop statement. • arealisticdreamer.weebly.com