Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills-2 4800153-3 1435/1436 Department of Computer Science.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Structure of a C program
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
CHAPTER 6: PROBLEM SOLVING CONCEPTS FOR THE COMPUTER PROGRAMMING Lec. Ghader R. Kurdi.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
CPS120: Introduction to Computer Science
Lecture #5 Introduction to C++
C Programming Laboratory I. Introduction to C Language /* the first program for user */ #include int a=0; int main(void) { printf(“Hello World\n”); return.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Chapter 2: Java Fundamentals
Fundamental Programming: Fundamental Programming Introduction to C++
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic © In this session we will.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
CPS120: Introduction to Computer Science Variables and Constants.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
Numbers in ‘C’ Two general categories: Integers Floats
C++ Lesson 1.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Introduction to C++.
Introduction to C Programming Language
' C ' PROGRAMMING SRM-MCA.
Introduction to C Programming
INTRODUCTION c is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
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.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
פרטים נוספים בסילבוס של הקורס
Govt. Polytechnic,Dhangar
Variables in C Topics Naming Variables Declaring Variables
UMBC CMSC 104 – Section 01, Fall 2016
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Chapter 2: Introduction to C++.
C programming Language
WEEK-2.
Programming Language C Language.
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Getting Started With Coding
Presentation transcript:

Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Place photo here

The Objectives and the outcomes The Objectives: 1.To understand the basic concept of C programming. 2.To be familiar with the programming structure. 3.To be able to write a simple program, compile it and run it. The Outcomes: 1.Students should have brief knowledge about computers programming. 2.Students should know how programs are structured. 3.Students should be able to write and run a simple program.

Introduction to Programming and Programming language The original C was still too limiting, and not standardized, and so in 1983 an ANSI committee was established to formalize the language definition. It has taken until now (ten years later) for the ANSI (American National Standard Institute) standard to become well accepted and almost universally supported by Compilers. The first language developed was (BCPL) and the next upgraded version was (B). The language (B) was upgraded to (C) by Dennis Ritche of AT & T laboratories, USA. C was first used to write UNIX OS. (C) is a general purpose language. Bjarne Strousstrup added object orientation to (C) and developed (C++).

Structure of a program Every C program consists of one or more modules called functions. One of these functions is called main. The program begins by executing main function and accesses other functions, if any. Functions are written after or before main function separately. A function has: (1) heading consists of name with list of arguments (optional) enclosed in parenthesis, (2) argument declaration (if any) and (3) compound statement enclosed in two braces { } such that each statement ends with a semicolon. Comments, which are not executable statement, of necessary can be placed in between /* and */.

Structure of a program In other words, at this stage the programs considered will fit into the following general format: // Introductory comments // file name, programmer, when written or modified // what program does #include int main () { constant declarations variable declarations executable statements }

Displaying a message Example Let us begin with a simple C program that displays the message “Hello world”. //C hello world example #include int main() { printf("Hello world\n"); return 0; } Output Hello world

Computing with C // Sample program // IEA September 2013 // Reads values for the length and width of a rectangle // and returns the area of the rectangle. #include int main() { int length, breadth, area; printf("\nEnter the Length of Rectangle : "); scanf("%d", &length); printf("\nEnter the Breadth of Rectangle : "); scanf("%d", &breadth); area = length * breadth; printf("\nArea of Rectangle : %d \n", area); return (0); } Output : Enter the Length of Rectangle : 5 Enter the Breadth of Rectangle : 4 Area of Rectangle : 20

Problem Solving Tools 1.Edit: Program is created in the editor and stored on the disk 2.Compile: Compiler create Object code and stores on disk. 3.Link: Linker links the Object code with Libraries, creates result and stores it on disk. 4.Load: Loader prints program in memory. 5.Execute: CPU takes each instruction and executes it. Possibly storing new data Values as program execute.

Creating, Compiling, and Running Programs 1.Study the requirement specification for the application. 2.Analyze the problem and decide how to solve it. 3.Translate the algorithm produced at the previous step into a suitable high-level language. 4.Compile the program into machine language. 5.The object code produced by the compiler will then be linked with various function libraries that are provided by the system. 6.Run the compiled, linked and loaded program with test data. 7.The program can now be put into general use - though unless the testing was very comprehensive it is possible that at some future date more logical errors may become apparent.

Creating, Compiling, and Running Programs

The character set: Character set includes the basic building blocks of a language. C character set consists of: 1.Numeric Character Set: Alphabetic Character Set: A-Z, a-z 3.Special Character Set: #, ;, :,(comma) etc 4.Escape Character Set: they are used for formatting the output. It always starts with a back slash ( \ ). Some Examples are \n, \t, \b, \a

Tokens The smallest individual unit in a program is known as token. C has the tokens, like: Keywords, Identifiers, Literals, Punctuators, and Operators. Keywords Keywords or Reserved words are those words, which are reserved for a specific purpose and part of the language. Examples: auto, break, case, char, const, continue, default, do, double, else enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while.

Tokens Punctuators The following characters are used as punctuators (also known as separators) in C: * + ( ), -, ; : * … = # Identifiers Words that are not reserved or keywords are called user defined words or identifiers. Identifiers must follow the following rules: 1.Can be composed of alphabets (A-Z or a-z), numbers (0 to 9) and underscore “_” 2.The first character must be an alphabet or an underscore “_”. 3.Identifier must be unique. 4.Blank Spaces are not allowed. 5.They are case sensitive i.e. Val and val are different Examples: Roll_number, r_no, Z, A1234_BC etc. Use the name of the identifier that is self-explanatory e.g. employee_name, student_name etc.

Data type: Data types are means to identify the type of data and associated operations of handling it. C data types are of two types; namely fundamental data types and derived data type. Fundamental data types Derived data type

Fundamental data types Data type:

Fundamental data types

Data type: Derived data type From the fundamental types, other types can be derived, using the declaration operators, e.g. Arrays.

Constants and Variables Constants (Literals): Constants are identifiers, which do not change its stored value during executing the program. There are 4 basic types of constants: 1.Integer constants: It is an integer valued number written in three different number system types, namely; decimal (base 10), octal(base8), and hexadecimal(base 16). 2.Floating point constants: It is a decimal number (i.e.; base 10) with a decimal point or an exponent or both. Ex; 32.65,0.654, 0.2E-3, 2.65E10 etc. These numbers have greater range than integer constants. 3.Character constants: It is a single character enclosed in single quotes like ′a′. ′3′, ′?′, ′A′, etc. each character has an ASCII to identify. For example ′A′ has the ASCII code 65, ′3′ has the code 51 and so on. 4.String constants: it consists of any number of consecutive characters enclosed in double quotes. Ex: const char *HELLO2 = "Howdy";

Constants and Variables Variables A variable is an identifier that has a changeable value during the execution of a program. 1.Variable Declaration: Declare a variable means to allocate a memory location to hold the value of this variable. 2.Defining a variable: each variable should have an Identifier, which is the variable name that you will use during the program, and in fact it is translated to an address of the memory location. 3.Data Type: it shows the type of the value that will be stored in this variable, such as Data_Type Identifier; int number1;

There are different types of variables such as: 1.Character variable (To store characters) 2.Integer variable (To store whole numbers) 3.Float variable (To store floating point numbers) 4.Boolean variable (To store two values true/false) e.g.: int a,b,c,d=10; (you can also initialize at the time of declaration). Constants and Variables Variables