Introduction to C Programming

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
Introduction to C Programming
Basic Input/Output and Variables Ethan Cerami New York
C PROGRAMMING LECTURE 17 th August IIT Kanpur C Course, Programming club, Fall by Deepak Majeti M-Tech CSE
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Week 1 Algorithmization and Programming Languages.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
© Copyright by Deitel 1 Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple.
CSCE 206 Structured Programming in C
Chapter 6 JavaScript: Introduction to Scripting
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Revision Lecture
Chapter 2 - Introduction to C Programming
By: Syed Shahrukh Haider
Introduction to C Programming
Chapter 7 - JavaScript: Introduction to Scripting
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
JavaScript: Introduction to Scripting
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Chapter 2 - Introduction to C Programming
Lecture3.
Introduction to Java Applications
Chapter 2 - Introduction to C Programming
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 1 Fundamentals of C
DATA TYPES There are four basic data types associated with variables:
Course Outcomes of Programming In C (PIC) (17212, C203):
Introduction to C Programming
Chapter 7 - JavaScript: Introduction to Scripting
Data Types and Arithmetic in C
Introduction to C Programming
Presentation transcript:

Introduction to C Programming 06/04/2019 Introduction to C Programming Dr. Nouf Aljaffan naljaffan@ksu.edu.sa Nouf Aljaffan (C) 2018

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

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

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

Multiple printfs Nouf Aljaffan (C) 2018

Avoid Single-Argument printf With newline Without newline Nouf Aljaffan (C) 2018

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

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

Arithmetic in C Nouf Aljaffan (C) 2018

Rules of Operator Precedence Nouf Aljaffan (C) 2018

Decision Making: Equality and Relational Operators Nouf Aljaffan (C) 2018

06/04/2019 Nouf Aljaffan (C) 2018 Nouf Aljaffan (C) 2018

06/04/2019 Nouf Aljaffan (C) 2018 Nouf Aljaffan (C) 2018

06/04/2019 Nouf Aljaffan (C) 2018 Nouf Aljaffan (C) 2018

Nouf Aljaffan (C) 2018

are reserved words of the language Nouf Aljaffan (C) 2018

Conclusion Program structure printf & scanf Arithmatics Equality and rational operators Keywords Nouf Aljaffan (C) 2018

Any Question! Nouf Aljaffan (C) 2018

Exercises Nouf Aljaffan (C) 2018

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

Exercise 2 Convert the algorithm to C source code Nouf Aljaffan (C) 2018

Exercise 3 Convert the algorithm to C source code Nouf Aljaffan (C) 2018

References C how to program, 8\e, by P. and H. Deitels , Chapter 2 Nouf Aljaffan (C) 2018