# Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Size: px
Start display at page:

Transcription

1 Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite number of steps. Characteristics of algorithms: Must have Well-ordered instructions Unambiguous operations Must produce at least one output Must be guaranteed to terminate May take zero or more inputs. Algorithms can be represented as step-form, Pseudo-code, Flow chart, Nasi-Schneiderman. Key features of an algorithm: Algorithms must have the following key features: a. Sequence (also known as process) b. Decision (also known as selection) c. Repetition (also known as iteration or looping) Sequence: Means that each step or process in the algorithm is executed in the specified order. Decision: In an algorithm the outcome of a decision is either true or false and it is based on some condition which will result in either true or false. Example: if marks greater than 35 then result is pass. The general form of decision is If <preposition> then <statement> The preposition is the condition and the statement is a set of statements executed for the truth value of the preposition. The other form is If <preposition> then <statement1> else <statement2> Here if the preposition evaluated to true statement1 is executed otherwise statement2 will be executed. Repetition constructs: Repetition can be implemented using the constructs like repeat loop, while loop and if then.. goto loop. Repeat loop is used to repeat or iterate a statement or sequence of statements until some condition becomes true. The general form of repeat loop is: repeat Statement 1 Statement 2

2 . Statement N until <condition> Here the loop is executed at least once since the condition is test at exit level. Some times this may lead to errors. While construct: The while construct repeats a statement or set of statements as long as the condition is true. The general form of while is: While <condition> begin Statement 1 Statement 2. Statement N end if.. goto construct: This is another looping construct. The general form of this construct is: Label: N Statement 1 Statement 2. Statement N if <condition> then goto N Example: Write an algorithm to check whether a given number is prime or not? Figure 1 Algorithm to check whether a given number is prime or not

3 Strategy for designing algorithm: There are three steps in the design of an algorithm. They are investigation step, top-down step and the stepwise refinement step. Investigations step: 1. Identify the outputs needed 2. Identify the input variables available 3. Identify the major decisions and conditions 4. Identify the statements required to transform inputs into outputs 5. Identify the environment available Top-down development step: 1. Devise the overall problem solution by identifying the major components of the system. The goal is to divide the problem into small manageable pieces that can be solved separately. 2. Verify the feasibility of breaking up the overall problem solution. Here the basic idea is to check that each small piece of solution is independent, and form the solution when they are integrated. Stepwise refinement: 1. Work out each and every detail for each small piece of manageable solution procedure. 2. Decompose any solution procedure into further smaller pieces and iterate until the desired level of detail is achieved. 3. Group processes together which have some commonality 4. Group variables together which have some appropriate commonality 5. Test each small procedure for its detail and correctness and its interfacing with the other small procedures. Tracing an algorithm to depict logic: An algorithm is a collection of procedures that result in providing solution to a problem. Tracing an algorithm primarily involves tracking the outcome of every procedure in the order they are placed. Tracking in tern means verifying every procedure one by one to determine and confirm the corresponding result that is to be obtained. This is in turn can be traced to offer an overall output from the implementation of the algorithm as a whole. Thus algorithm tracing means verifying the algorithm for its correctness with all possible inputs. Specification for converting algorithms into programs: Once the algorithm for the solution of a problem is formed and represented using any one of the tools like pseudo-code, flowchart or step-form, it has to be transformed into some programming language code. The general procedure to convert an algorithm into a program is: Code the algorithm into a program: Understand the syntax and control structures used in the language that has been selected and write the equivalent program instructions based on the algorithm that was created. Each statement in the algorithm may require one or more lines of programming code.

4 Desk-check the program: Check the program code by employing the desk-check method and make sure that the sample data selected produces the expected output. Evaluate and modify, if necessary, the program: Based on the outcome of the deskcheck the program, make program code changes, if necessary, or make changes to the original algorithm, if need be. Do not reinvent the wheel: If the design code already exists, modify, do not remake it. Flowchart: A flowchart is a graphical representation of an algorithm. A flowchart comprises of a set of standard shaped boxes that are interconnected by flow lines to represent an algorithm. Flowcharts play a vital role in the programming of a problem and are quiet helpful in understanding the logic of complicated and lengthy problems. Flowcharts facilitate communication between programmers and business persons. Once a flowchart is drawn it is easy to program in any high-level language and also helpful in explaining the program to others. Flowchart is must for better documentation of a complex problem. Standards for flowcharts: The following standards should be adhered to while drawing flowcharts: Flowchart must be drawn on white, unlined 8 ½ x11 paper, on one side only. Flowcharts start on the top of the page and flow down and to the right Only standard flowcharting symbols should be used. A template to draw the final version of flowchart should be used. The contents of each symbol should be printed legibly. English should be used in flowcharts, not programming language. The flowchart for each subroutine, if any, must appear on a separate page. Each subroutine must start with a terminal symbol with the subroutine name and a symbol labeled return at the end. Draw the arrows between symbols with a straight edge and use arrowheads to indicate the direction of the logic flow. Guidelines for drawing a flowchart: Flowcharts are usually drawn using standard symbols; however some special symbols can also be developed when required. Some standard symbols frequently required for flowcharting many computer programs are shown in Figure 2. Some of the guidelines in flowcharting are: In drawing a proper flowchart, all necessary requirements should be listed out in a logical order. There should be a logical start and stop to the flowchart. The flowchart should be clear, neat, and easy to follow. There should be no ambiguity in understanding the chart. The usual direction of the flow of a procedure or system is from left to right or top to bottom.

5 Only one flow line should emerge from a process symbol. Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, can leave the decision symbol. Only one flow line is used in conjunction with a terminal symbol. The writing within standard symbols should be brief. If the flowchart becomes complex, connector symbols should be used to reduce the number of flow lines. The intersection of flow lines should be avoided to make the flowchart a more effective and better way of communication. Validity of the flowchart should be tested passing simple test data through it. A sequence of steps or processes that are to be executed in a particular order is shown using process symbols connected with flow lines. Selection of a process or step is depicted by the decision making and process symbols. Only one input indicated by one incoming flow line and one output flowing out of this structure exists. Decision symbols and process symbols are connected by flow lines. Iteration or looping is depicted by a combination of process and decision symbols placed in proper order. Figure 2 Flowchart symbols Advantages of flow charts: Communication: Flowcharts are better way of communicating the logic of a system to all concerned.

6 Effective analysis: Problems can be analysed in a more effective manner using flowcharts. Proper documentation: Program flowcharts serve as a good program documentation needed for various development phases. Efficient coding: Flowcharts act as a guide or blueprint during the systems analysis and program development phase. Proper debugging: Flowcharts help in the debugging process. Efficient program maintenance: The maintenance of an operating program becomes easy with the help of a flowchart. Limitations: Complex logic: Some time the program logic is quite complicated. In such situations a flowchart becomes complex and clumsy. Alterations and modifications: The flowcharts need to be completely redrawn when alterations are required. Reproduction: Since the flowchart symbols cannot by retyped in, the reproduction of a flowchart becomes a problem. Loss of objective: The essentials of what has to be done can be easily be lost in the technical details f how it is to be done. Example: Problem 1: Draw a flowchart to find the roots of a quadratic equation. Figure 3 Flowchart for finding the root of a quadratic equation

7 Problem 2: Prepare a flowchart to read the marks of a student and classify them into different grades. If the marks secured are greater than or equal to 90, the student is awarded Grade A; if they are greater than or equal to 80 but less than 90, Grade B is awarded; if they are greater than or equal to 65 but less than 80, Grade C is awarded; otherwise Grade D is awarded. Figure 4 Solution to problem 2. Introduction to C Programming: Standardizations: Tokens: Tokens are the basic lexical building blocks of source code. Created by combining characters according to the rules of the programming language. There are five classes of tokes namely identifiers, reserved words, operators, and constants. Identifiers: An identifier or name is a sequence of characters created by a programmer to identify or name or specific object. It is formed by a sequence of letters, digits, and underscores. In C, variables, arrays, functions and labels are named as identifiers. Rules for creating identifiers: 1. First character must be an alphabetic character (lower-case or upper-case letters) or an underscore _. 2. All characters must be alphabetic characters, digits, or underscores.

8 3. The first 31 characters of the identifier are significant. 4. Cannot duplicate a keyword ( a keyword is one which has special meaning to C). Examples: number1, roll_number, name etc. Keywords: These are the vocabulary of C. These words have predefined uses and cannot be used for any other purpose in a C program. They are always written in lowercase letters. The complete list of C keywords are: 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 unon unsigned void volatile while keywords were added in in C99: inline restrict _Bool _Complex and Imaginary. Constant: A constant is an explicit data value written by the programmer and its value is known to the compiler at compile time. Compiler may deal with the value of constant in several ways depending on the type of constant and its context. Ex: the binary equivalent of the constant may be inserted directly into the output code stream. C permits integer constant, floating point constants, character constants and string constants. Integer constant is always assumed to be of type int and can be expressed in decimal, octal, and hexadecimal notations. Examples: 523, 0234 (0ctal), 0x34ab (hexadecimal) A floating-point constant consists of an integer part, a decimal point, a fractional part, and an exponent field containing an e or E followed by an integer. Both the integer and the fractional parts are digit sequences. Example: 0.234F, f, 2.345E-2 or 2.345e-2 etc. Figure Specification of different constants.

9 A character constant consists of a single character enclosed in single quotes. Example: c, \n, + etc. A String constant is a sequence of characters enclosed in double quotes. The compiler stores the character sequence in an available memory. It also records the address of the first character and appends an additional null character ( \0 ) at the end of the sequence. Example: CBIT, Hyd. Assignment operator: Is the single equal to sign (=). The general form of the assignment operator is Variable_name = expression; Example: c=a+b; I=10; The assignment operator replaces the contents the location c with the summed contents of a and b, contents of I with the contents of I plus one respectively. The operand to the left of the assignment operator is an lvalue that denotes left value. Operators: An operator is a symbol that specifies the mathematical, logical, or relational operation to be performed. C operators are classified into arithmetic, assignment, relational, equality, logical, bitwise and other categories. Figure 5: Different operators

10 Figure 6: Classification of operators in C language Arithmetic operators in C: These operators are used to perform arithmetic operations like addition, subtraction, multiplication, division etc. There are three types of operators in C: binary, unary and ternary. Binary operators: Needs two operands. C provides five basic arithmetic binary operators. These are: o Except the for remainder (%), all other arithmetic operators can accept a mix of integers and real operands. o If operands are integers, the result will be an integer and if one or both of the operands are reals then the result will be a real (or double to be exact). o When both operands of the division operator (/) are integers, the division is performed as an integer division not the normal division. Integer division always results in an integer outcome. i.e. the result is always rounded off by ignoring the remainder. Example 5/2 gives 2, -5/2 gives -2. o It is not possible to divide a number by zero which results in division-by-zero exception. o To obtain a real division one of the operand must be a real operand. o The remainder operator (%) always expects integers for both of its operands. It returns the integer part of remainder obtained after dividing the operands. Example: 5%2=1. The outcome of an arithmetic operation to be large for storing in a designated variable. This situation is called an overflow.

11 Unary operators: The unary operator negates the value of its operand (clearly, a signed number). A numeric constant is assumed positive unless it is preceded by the negative operator. That is, there is no unary +. It is implicit. Remember that -x does not change the value of x at the location where it permanently resides in memory. Unary increment and decrement operators ++ and -- operators increment or decrement the value in a variable by 1. Basic rules for using ++ and operators: The operand must be a variable but not a constant or an expression. The operator ++ and -- may precede or succeed the operand. Postfix: (a) x = a++; First action: store value of a in memory location for variable x. Second action: increment value of a by 1 and store result in memory location for variable a. (b) y = b ; First action: put value of b in memory location for variable y. Second action: decrement value of b by 1 and put result in memory location for variable b. Prefix : (a) x = ++a; First action: increment value of a by 1 and store result in memory location for variable a. Second action: store value of a in memory location for variable x. (b) y = b; First action: decrement value of b by 1 and put result in memory location for variable b. Second action: put value of b in memory location for variable y. Relational operators: C provides six relational operators for comparing numeric quantities. Relational operators evaluate to 1, representing the true outcome, or 0, representing the false outcome.

12 Logical operators: C provides three logical operators for forming logical expressions. Like the relational operators, logical operators evaluate to 1 or 0. Logical negation is a unary operator that negates the logical value of its single operand. If its operand is non-zero, it produces 0, and if it is 0, it produces 1. Logical AND produces 0 if one or both its operands evaluate to 0. Otherwise, it produces 1. Logical OR produces 0 if both its operands evaluate to 0. Otherwise, it produces 1. Bitwise operators: C provides six bitwise operators for manipulating the individual bits in an integer quantity. Bitwise operators expect their operands to be integer quantities and treat them as bit sequences. Bitwise negation is a unary operator that complements the bits in its operands. Bitwise AND compares the corresponding bits of its operands and produces a 1 when both bits are 1, and 0 otherwise. Bitwise OR compares the corresponding bits of its operands and produces a 0 when both bits are 0, and 1 otherwise. Bitwise exclusive or compares the corresponding bits of its operands and produces a 0 when both bits are 1 or both bits are 0, and 1 otherwise.

13 Conditional operator: The conditional operator has three expressions. It has the general form expression1? expression2 : expression3 First, expression1 is evaluated; it is treated as a logical condition. If the result is non-zero, then expression2 is evaluated and its value is the final result. Otherwise, expression3 is evaluated and its value is the final result. For example,int m = 1, n = 2, min; min = (m < n? m : n); /* min is assigned a value 1 */ In the above example, because m is less than n, m<n expression evaluates to be true, therefore, min is assigned the value m, i.e., 1. Comma operator: This operator allows the evaluation of multiple expressions, separated by the comma, from left to right in order and the evaluated value of the rightmost expression is accepted as the final result. The general form of an expression using a comma operator is Expression M = (expression1, expression2,,expression N); where the expressions are evaluated strictly from left to right and their values discarded, except for the last one, whose type and value determine the result of the overall expression. Sizeof operator:

14 C provides a useful operator, sizeof, for calculating the size of any data item or type. It takes a single operand that may be a type name (e.g., int) or an expression (e.g.,100) and returns the size of the specified entity in bytes.the outcome is totally machinedependent. For example: EXPRESSION EVOLUATION: PRECEDENCE & ASSOCIATIVITY: Evaluation of an expression in C is very important to understand. Unfortunately there is no BODMAS rule in C language as found in algebra. The precedence of operators determines the order in which different operators are evaluated when they occur in the same expression. Operators of higher precedence are applied before operators of lower precedence.

15

### Operators and Type Conversion. By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE

Operators and Type Conversion By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE Introduction An operator is a symbol which represents a particular operation that can be performed on some data.

### DEPARTMENT OF MATHS, MJ COLLEGE

T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

### Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

### A flow chart is a graphical or symbolic representation of a process.

Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of

### Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

### UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . \$, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

### LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

### Fundamentals of Programming

Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

### Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

### Programming in C++ 4. The lexical basis of C++

Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++

### Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

### I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

I Internal Examination Sept. 2018 Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. [I]Very short answer questions (Max 40 words). (5 * 2 = 10) 1. What is

### Operators in C. Staff Incharge: S.Sasirekha

Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C

### Unit 3. Operators. School of Science and Technology INTRODUCTION

INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

### C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

### Presented By : Gaurav Juneja

Presented By : Gaurav Juneja 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 of UNIX are written

### Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

### 3. Java - Language Constructs I

Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

### UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

### C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

### Chapter 4. Operations on Data

Chapter 4 Operations on Data 1 OBJECTIVES After reading this chapter, the reader should be able to: List the three categories of operations performed on data. Perform unary and binary logic operations

### COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS S.LAWRENCE CHRISTOPHER, M.C.A., B.Ed., LECTURER IN COMPUTER SCIENCE PONDICHERRY

### Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

### Programming in C++ 5. Integral data types

Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long

### CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

### Review of the C Programming Language

Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

### Operators and Expressions:

Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

### Engineering Computing I

Engineering Computing I Types, Operators, and Expressions Types Operators Expressions 2 1 2.1 Variable Names Names are made up of letters and digits The first character must be a letter The underscore

### Data Types and Variables in C language

Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

### Programming. C++ Basics

Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

### MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards Language Reference Manual Introduction The purpose of

### GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

### ARG! Language Reference Manual

ARG! Language Reference Manual Ryan Eagan, Mike Goldin, River Keefer, Shivangi Saxena 1. Introduction ARG is a language to be used to make programming a less frustrating experience. It is similar to C

### XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

XC Specification IN THIS DOCUMENT Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage

### Programming for Engineers Iteration

Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

### .Net Technologies. Components of.net Framework

.Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.

### Chapter 3: Operators, Expressions and Type Conversion

101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

### Unit II. (i) Computer Programming Languages

Unit II. (i) Computer Programming Languages Need of a computer programming language: A programming language is an artificial language designed to communicate instructions to a computer. Thousands of different

### CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

### 4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

### Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other

### Programming Lecture 3

Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

### PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

### More Programming Constructs -- Introduction

More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

### P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)

FACULTY: Ms. Saritha P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) SUBJECT / CODE: Programming in C and Data Structures- 15PCD13 What is token?

### BCA-105 C Language What is C? History of C

C Language What is C? C is a programming language developed at AT & T s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. C seems so popular is because it is

### ANSI C Programming Simple Programs

ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

### 1 Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

### VARIABLES AND CONSTANTS

UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data

### Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

### A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object

### BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

### PROBLEM SOLVING AND OFFICE AUTOMATION. A Program consists of a series of instruction that a computer processes to perform the required operation.

UNIT III PROBLEM SOLVING AND OFFICE AUTOMATION Planning the Computer Program Purpose Algorithm Flow Charts Pseudo code -Application Software Packages- Introduction to Office Packages (not detailed commands

### Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

### Basic Elements of C. Staff Incharge: S.Sasirekha

Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase

### Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

Programming in C and Data Structures [15PCD13/23] 1 PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Course objectives: The objectives of this course is to make students

### University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.

### STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

### Programming and Data Structures

Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

### XQ: An XML Query Language Language Reference Manual

XQ: An XML Query Language Language Reference Manual Kin Ng kn2006@columbia.edu 1. Introduction XQ is a query language for XML documents. This language enables programmers to express queries in a few simple

### A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

### Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

### Introduction to Programming

Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines

### C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

### These are reserved words of the C language. For example int, float, if, else, for, while etc.

Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

### Differentiate Between Keywords and Identifiers

History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)

### Full file at

Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

### CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section :

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart ANS. Flowchart:- A diagrametic reperesentation of program is known as flowchart Symbols Q-2) Explain basic structure of c language

### Language Reference Manual simplicity

Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

### The C++ Language. Arizona State University 1

The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

### Operators. Java operators are classified into three categories:

Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

### EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6

### Decaf Language Reference Manual

Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

### INTRODUCTION 1 AND REVIEW

INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

### By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize

### Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

### Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

### Chapter 7. Additional Control Structures

Chapter 7 Additional Control Structures 1 Chapter 7 Topics Switch Statement for Multi-Way Branching Do-While Statement for Looping For Statement for Looping Using break and continue Statements 2 Chapter

### Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Q1. Explain the structure of a C program Structure of the C program is shown below: Preprocessor Directives Global Declarations Int main (void) Local Declarations Statements Other functions as required

### The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

### The Arithmetic Operators

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

### Number System. Introduction. Decimal Numbers

Number System Introduction Number systems provide the basis for all operations in information processing systems. In a number system the information is divided into a group of symbols; for example, 26

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2. Lexical Elements & Operators

Chapter 2. Lexical Elements & Operators Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr The C System

### Introduction to C# Applications

1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

### Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

### INTRODUCTION TO C A PRE-REQUISITE

This document can be downloaded from www.chetanahegde.in with most recent updates. 1 INTRODUCTION TO C A PRE-REQUISITE 1.1 ALGORITHMS Computer solves a problem based on a set of instructions provided to

### Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

### DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special

### Information Science 1

Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

### C - Basic Introduction

C - Basic Introduction C is a general-purpose high level language that was originally developed by Dennis Ritchie for the UNIX operating system. It was first implemented on the Digital Equipment Corporation

### Language Reference Manual

Programming Languages and Translators Language Reference Manual ART: Animation Rendering Tool Brett Jervey - baj2125 Gedion Metaferia - gym2103 Natan Kibret - nfk2105 Soul Joshi - srj2120 October 26, 2016

### Types and Expressions. Chapter 3

Types and Expressions Chapter 3 Chapter Contents 3.1 Introductory Example: Einstein's Equation 3.2 Primitive Types and Reference Types 3.3 Numeric Types and Expressions 3.4 Assignment Expressions 3.5 Java's

### Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

### CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values