Download presentation
Presentation is loading. Please wait.
1
Introduction to C Programming
06/04/2019 Introduction to C Programming Dr. Nouf Aljaffan Nouf Aljaffan (C) 2018
2
Objectives Write simple C programs.
Use simple input and output statements. Use the fundamental data types. Learn computer memory concepts. Use arithmetic operators. Learn the precedence of arithmetic operators. Write simple decision making statements. Begin focusing on secure C programming practices Nouf Aljaffan (C) 2018
3
Structure of a .c file Add Comments Insert pre-processor definitions
06/04/2019 Structure of a .c file Add Comments Line comment: // my comment multi-line comments : /* my comments */ Insert pre-processor definitions #include < [file name & extension] > Add function prototypes and variable declarations Define main function int main( void ) { [function body] } Define other functions Nouf Aljaffan (C) 2018 Nouf Aljaffan (C) 2018
4
Structure of a .c file An Output Statement
06/04/2019 Structure of a .c file An Output Statement printf( “this will be displayed on screen” ); The backslash (\) as used here is called an escape character. Nouf Aljaffan (C) 2018 Nouf Aljaffan (C) 2018
5
Multiple printfs Nouf Aljaffan (C) 2018
6
Avoid Single-Argument printf
With newline Without newline Nouf Aljaffan (C) 2018
7
Adding Two Integers Add Comments Insert pre-processor definitions
06/04/2019 Adding Two Integers Add Comments Insert pre-processor definitions Define main function Declare variables [DataType] [VariableName]; Variable names are case sensitive User scanf to read variables by a user at the keyboard scanf(“format control string,”, &variableName) computes the sum of two values Nouf Aljaffan (C) 2018 Nouf Aljaffan (C) 2018
8
Input / Output More format specifiers
printf (); //used to print to console(screen) example: printf(“%c”, ’a’); scanf (); //used to take an input from console(user). example: scanf(“%d”, &a); %c The character format specifier. %d The integer format specifier. %i The integer format specifier (same as %d). %f The floating-point format specifier. %o The unsigned octal format specifier. %s The string format specifier. %u The unsigned integer format specifier. %x The unsigned hexadecimal format specifier. %% Outputs a percent sign. C Course, Programming club, Fall 2008
9
Arithmetic in C Nouf Aljaffan (C) 2018
10
Rules of Operator Precedence
Nouf Aljaffan (C) 2018
11
Decision Making: Equality and Relational Operators
Nouf Aljaffan (C) 2018
12
06/04/2019 Nouf Aljaffan (C) 2018 Nouf Aljaffan (C) 2018
13
06/04/2019 Nouf Aljaffan (C) 2018 Nouf Aljaffan (C) 2018
14
06/04/2019 Nouf Aljaffan (C) 2018 Nouf Aljaffan (C) 2018
15
Nouf Aljaffan (C) 2018
16
are reserved words of the language
Nouf Aljaffan (C) 2018
17
Conclusion Program structure printf & scanf Arithmatics
Equality and rational operators Keywords Nouf Aljaffan (C) 2018
18
Any Question! Nouf Aljaffan (C) 2018
19
Exercises Nouf Aljaffan (C) 2018
20
Exercise 1 Identify and correct the errors in each of the following statements: printf( "The value is %d\n", &number ); scanf( "%d%d", &number1, number2 ); if ( c < 7 );{ printf( "C is less than 7\n" ); } if ( c => 7 ) { printf( "C is greater than or equal to 7\n" ); Nouf Aljaffan (C) 2018
21
Exercise 2 Convert the algorithm to C source code
Nouf Aljaffan (C) 2018
22
Exercise 3 Convert the algorithm to C source code
Nouf Aljaffan (C) 2018
23
References C how to program, 8\e, by P. and H. Deitels , Chapter 2
Nouf Aljaffan (C) 2018
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.