Page 1 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , UNIT 1 - FUNDAMENTALS OF COMPUTERS:, 1. INTRODUCTION TO COMPUTERS:, The word computer comes from the word “compute”, which means, “to calculate”., Thereby, a computer is an electronic device that can perform arithmetic operations at, high speed, A computer is also called a data processor because it can store, process, and retrieve, data whenever desired, , 1.1 Computer Definition, Computer is an advanced electronic device that takes data as an input from the user and, processes it under the control of a set of instructions, produces a result and saves it for future use., , 1.2 Characteristics of Computers, The followings are the characteristics of computer:, 1) Automatic: Given a job, computer can work on it automatically without human, interventions, 2) Speed: Computer can perform data processing jobs very fast, usually measured in, microseconds (10-6), nanoseconds (10-9), and picoseconds (10--12), 3) Accuracy: Accuracy of a computer is consistently high and the degree of its accuracy, depends upon its design., 4) Diligence: Computer is free from monotony, tiredness, and lack of concentration. It, can continuously work for hours without creating any error and without grumbling, 5) Versatility: Computer is capable of performing almost any task, if the task can be, reduced to a finite series of logical steps, 6) Power of Remembering: Computer can store and recall any amount of information,, because of its secondary storage capability. It forgets or looses certain information only, when it is asked to do so, 7) No I.Q.: A computer does only what it is programmed to do. It cannot take its own, decision in this regard, 8) No Feelings: Computers are devoid of emotions. Their judgment is based on the, instructions given to them in the form of programs that are written by programmer., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 1
Page 2 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , 1.3 Evolution and History of Computers, Blaise Pascal invented the first mechanical adding machine in 1642, Baron Gottfried Wilhelm von Leibniz invented the first calculator for multiplication in, 1671, Keyboard machines originated in the United States around 1880, Around 1880, Herman Hollerith came up with the concept of punched cards that were, extensively used as input media until late 1970s, Charles Babbage is considered to be the father of modern digital computers, He designed “Difference Engine” in 1822, He designed a fully automatic analytical engine in 1842 for performing basic, arithmetic functions, His efforts established a number of principles that are fundamental to the design, of any digital computer-, , 1.4 Types of Computers, Followings are the types of computers, i., ii., iii., iv., v., , Microcomputer, Minicomputer, Mainframe computer, Supercomputer, Workstation, , i. Microcomputer:, Microcomputer is also known as a personal computer., It is a general-purpose computer that is designed for individual use., It has a microprocessor as a central processing unit, memory, storage area, input unit and, output unit., Laptops and desktop computers are examples of microcomputers., They are suitable for personal work that may be making an assignment, watching a, movie, or at office for office work., Characteristics of a microcomputer:, o, , It is the smallest in size among all types of computers., , o, , A limited number of software can be used., , o, , It is designed for personal work and applications. Only one user can work at a time., , o, , It is less expansive and easy to use., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 2
Page 3 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , o, , It does not require the user to have special skills or training to use it., , o, , Generally, comes with single semiconductor chip., , o, , It is capable of multitasking such as printing, scanning, browsing, watching videos, etc., , ii. Minicomputer:, It is a midsize multiprocessing computer., It consists of two or more processors and can support 4 to 200 users at one time., Minicomputers are used in institutes and departments for tasks such as billing, accounting, and inventory management., A minicomputer lies between the mainframe and microcomputer as it is smaller than, mainframe but larger than a microcomputer., Characteristics of minicomputer:, o, , It is light weight that makes it easy to carry and fit anywhere., , o, , It is less expensive than mainframe computers., , o, , It is very fast compared to its size., , o, , It remains charged for a long time., , o, , It does not require a controlled operational environment., , iii. Mainframe computer:, Mainframe computers are designed to support hundreds or thousands of users, simultaneously., They can support multiple programs at the same time. It means they can execute different, processes simultaneously., These features of mainframe computers make them ideal for big organizations like, banking and telecom sectors, which need to manage and process high volume of data., Characteristics of Mainframe Computers:, o, , It can process huge amount of data, e.g. millions of transactions in a second in the, banking sector., , o, , It has a very long life. It can run smoothly for up to 50 years after proper installation., , o, , It gives excellent performance with large scale memory management., , o, , It has the ability to share or distribute its workload among other processors and, input/output terminals., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 3
Page 4 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , o, , There are fewer chances of error or bugs during processing in mainframe computers. If, any error occurs it can fix it quickly without affecting the performance., , o, , It has the ability to protect the stored data and other ongoing exchange of information and, data., , iv. Super computer:, , , , , , , Supercomputers are the biggest and fastest computers., They are designed to process huge amount of data., A supercomputer can process trillions of instructions in a second., It has thousands of interconnected processors., Supercomputers are particularly used in scientific and engineering applications such as, weather forecasting, scientific simulations and nuclear energy research., The first supercomputer was developed by Roger Cray in 1976., Characteristics or applications of supercomputers:, o, , It has the ability to decrypt your password to enhance protection for security reasons., , o, , It produces excellent results in animations., , o, , It is used for virtual testing of nuclear weapons and critical medical tests., , o, , It can study and understand climate patterns and forecast weather conditions, , o, , It helps in designing the flight simulators for pilots at the beginner level for their training., , o, , It helps in extracting useful information from data storage centers or cloud system. For, example, in insurance companies., , o, , It has played a vital role in managing the online currency world such as stock market and, bitcoin., , o, , It helps in the diagnosis of various critical diseases and in producing accurate results in, brain injuries, strokes, etc., , o, , It helps in scientific research areas by accurately analyzing data obtained from exploring, the solar system, satellites, and movement of Earth., , o, , It also used in a smog control system where it predicts the level of fog and other, pollutants in the atmosphere., , v. Workstation:, Workstation is a single user computer that is designed for technical or scientific, applications., It has a faster microprocessor, a large amount of RAM and high speed graphic adapters., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 4
Page 5 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , It generally performs a specific job with great expertise; accordingly, they are of different, types such as graphics workstation, music workstation and engineering design, workstation., Characteristics of workstation computer:, o, , It is a high-performance computer system designed for a single user for business or, professional use., , o, , It has larger storage capacity, better graphics, and more powerful CPU than a personal, computer., , o, , It can handle animation, data analysis, CAD, audio and video creation and editing., , 1.5 Basic Organization of a Digital Computer, , Input Unit: A input unit of a computer system performs the following functions:, It accepts (or reads) instructions and data from outside world, It converts these instructions and data in computer acceptable form, It supplies the converted instructions and data to the computer system for further, processing, Output Unit: An output unit of a computer system performs the following functions:, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 5
Page 6 :
I BSc, , , , , , , , Computer Fundamentals and Programming in C, , It accepts the results produced by the computer, which are in coded form and hence,, cannot be easily understood by us, It converts these coded results to human acceptable (readable) form, It supplies the converted results to outside world, Central Processing Unit:, It is the brain of a computer system, It is responsible for controlling the operations of all other units of a computer, system, Arithmetic Logic Unit: Arithmetic Logic Unit of a computer system is the place where, the actual executions of instructions take place during processing operation, Control Unit: Control Unit of a computer system manages and coordinates the, operations of all other components of the computer system, Storage Unit: The storage unit of a computer system holds (or stores) the following :, Data and instructions required for processing (received from input devices), Intermediate results of processing, Final results of processing, before they are released to an output device, There are two types of storage - primary and secondary storage, Primary storage, , , , , , , , , , UNIT 1, , Secondary storage, , Used to hold running program, instructions, Used to hold data, intermediate, results, and results of ongoing, processing of job(s), Fast in operation, Small Capacity, Expensive, Volatile (loses data on power, dissipation), , , , , , , , , Used to hold stored program, instructions, Used to hold data and information of, stored jobs, Slower than primary storage, Large Capacity, Lot cheaper that primary storage, Non Volatile (Retains data even, without power), , 2. NUMBER SYSTEMS, 2.1 Different types of Number systems, 1. Decimal number system, A positional number system, It has 10 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). Hence, its base = 10, The maximum value of a single digit is 9 (one less than the value of the base) § Each, position of a digit represents a specific power of the base (10), Arpitha K, Dept. of CS, , Mandya University, Mandya, , 6
Page 7 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , We use this number system in our day-to-day life, Example:, (2586)10 = (2 x 103) + (5 x 102) + (8 x 101) + (6 x 100), = 2000 + 500 + 80 + 6, 2. Binary number system, , , , , , , , A positional number system, It has only 2 symbols or digits (0 and 1). Hence its base = 2, The maximum value of a single digit is 1 (one less than the value of the base), Each position of a digit represents a specific power of the base (2), This number system is used in computers, Example:, (10101)2 = (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) x (1 x 20), = 16 + 0 + 4 + 0 + 1, = (21)10, , 3. Octal number system, , , , , , , A positional number system, It has total 8 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7). Hence, its base = 8, The maximum value of a single digit is 7 (one less than the value of the base), Each position of a digit represents a specific power of the base (8), Example:, (2057)8 = (2 x 83) + (0 x 82) + (5 x 81) + (7 x 80), = 1024 + 0 + 40 + 7, = (1071)10, , 4. Hexadecimal number system, A positional number system, It has total 16 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). Hence its, base = 16, The symbols A, B, C, D, E and F represent the decimal values 10, 11, 12, 13, 14 and 15, respectively, The maximum value of a single digit is 15 (one less than the value of the base), Each position of a digit represents a specific power of the base (16), Since there are only 16 digits, 4 bits (24 = 16) are sufficient to represent any hexadecimal, number in binary, Example:, (1AF) 16 = (1 x 162) + (A x 161) + (F x 160), = 1 x 256 + 10 x 16 + 15 x 1, = 256 + 160 + 15 = (431)10, Arpitha K, Dept. of CS, , Mandya University, Mandya, , 7
Page 8 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , 2.2 Conversion from one number system to another, , ****Refer Class Notes or Number System PDF for this topic****, 3. COMPUTER CODES, Computer codes are used for internal representation of data in computers, As computers use binary numbers for internal data representation, computer codes use, binary coding schemes, In binary coding, every symbol that appears in the data is represented by a group of bits, The group of bits used to represent a symbol is called a byte, As most modern coding schemes use 8 bits to represent a symbol, the term byte is often, used to mean a group of 8 bits, Commonly used computer codes are BCD, EBCDIC, and ASCII, , 3.1 BCD, In this code each decimal digit is represented by a 4-bit binary number., BCD is a way to express each of the decimal digits with a binary code., In the BCD, with four bits we can represent sixteen numbers (0000 to 1111). But in BCD, code only first ten of these are used (0000 to 1001)., The remaining six code combinations i.e. 1010 to 1111 are invalid in BCD., The most common BCD code is the 8421 BCD code. For example, if we look at table, we, find that the decimal digit 9 when represented in 8421 BCD is 1001, , Advantages of BCD Codes, , , It is very similar to decimal system., , , , We need to remember binary equivalent of decimal numbers 0 to 9 only., , Disadvantages of BCD Codes, , , The addition and subtraction of BCD have different rules., , , , The BCD arithmetic is little more complicated., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 8
Page 9 :
I BSc, , Computer Fundamentals and Programming in C, , , UNIT 1, , BCD needs more number of bits than binary to represent the decimal number. So, BCD is less efficient than binary., , 3.2 Gray Code, It is the non-weighted code and it is not arithmetic codes., That means there are no specific weights assigned to the bit position., It has a very special feature that, only one bit will change each time the decimal number, is incremented as shown in below figure., As only one bit changes at a time, the gray code is called as a unit distance code., The gray code is a cyclic code. Gray code cannot be used for arithmetic operation., , 3.3 ASCII, ASCII stands for American Standard Code for Information Interchange., It is a set of characters which, unlike the characters in word processing documents, allow, no special formatting like different fonts, bold, underlined or italic text., ASCII is computer code for the interchange of information between terminals., Originally it was designed to represent 128 characters (mainly from the alphabet)., Today different additions exist. They use extended versions of the table with additional, 128 characters. Each character is encoded with an 8 bit number (ranging from 0 to 255)., ASCII-7 uses 7 bits to represent a symbol and can represent 128 (27) different characters, ASCII-8 uses 8 bits to represent a symbol and can represent 256 (28) different characters, First 128 characters in ASCII-7 and ASCII-8 are same, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 9
Page 10 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , 3.4 Unicode, Why Unicode:, No single encoding system supports all languages, Different encoding systems conflict, Unicode features:, Provides a consistent way of encoding multilingual plain text, Defines codes for characters used in all major languages of the world, Defines codes for special characters, mathematical symbols, technical symbols,, and diacritics, Capacity to encode as many as a million characters, Assigns each character a unique numeric value and name, Reserves a part of the code space for private use, Affords simplicity and consistency of ASCII, even corresponding characters have, same code, Specifies an algorithm for the presentation of text with bi-directional behavior, Encoding Forms:, UTF-8, UTF-16, UTF-32, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 10
Page 11 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , 4. BOOLEAN ALGEBRA, An algebra that deals with binary number system, George Boole (1815-1864), an English mathematician, developed it for:, Simplifying representation, Manipulation of propositional logic, In 1938, Claude E. Shannon proposed using Boolean algebra in design of relay switching, circuits, Provides economical and straightforward approach, Used extensively in designing electronic circuits used in computers, , 4.1 Boolean Operators with Truth Tables, The table used to represent the Boolean expression of a logic gate function is commonly, called a Truth Table. A logic gate truth table shows each possible input combination to the gate, or circuit with the resultant output depending upon the combination of these input(s)., Then the four possible combinations of A and B for a 2-input logic gate is given as:, , , Input Combination 1. – “OFF” – “OFF” or ( 0, 0 ), , , , Input Combination 2. – “OFF” – “ON” or ( 0, 1 ), , , , Input Combination 3. – “ON” – “OFF” or ( 1, 0 ), , , , Input Combination 4. – “ON” – “ON” or ( 1, 1 ), , The following table gives a list of the common logic functions and their equivalent, Boolean notation., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 11
Page 12 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , i. AND Gate, For a 2-input AND gate, the output Q is true if BOTH input A “AND” input B are both, true, giving the Boolean Expression of: ( Q = A and B )., The Boolean Expression for a two input AND gate can be written as: A.B or just, simply AB without the decimal point., , ii. OR (Inclusive OR) Gate, For a 2-input OR gate, the output Q is true if EITHER input A “OR” input B is true,, giving the Boolean Expression of: ( Q = A or B )., , iii. NOT Gate (Inverter), For a single input NOT gate, the output Q is ONLY true when the input is “NOT” true,, the output is the inverse or complement of the input giving the Boolean Expression of:, ( Q = NOT A )., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 12
Page 13 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , iv. NAND (Not AND) Gate, For a 2-input NAND gate, the output Q is NOT true if BOTH input A and input B are, true, giving the Boolean Expression of: ( Q = not(A AND B) )., , v. NOR (Not OR) Gate, For a 2-input NOR gate, the output Q is true if BOTH input A and input B are NOT true,, giving the Boolean Expression of: ( Q = not(A OR B) )., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 13
Page 14 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , As well as the standard logic gates there are also two special types of logic gate function, called an Exclusive-OR Gate and an Exclusive-NOR Gate. The Boolean expression to indicate, an Exclusive-OR or Exclusive-NOR function is to a symbol with a plus sign inside a circle,, ( ⊕ )., a) EX-OR (Exclusive OR) Gate, For a 2-input Ex-OR gate, the output Q is true if EITHER input A or if input B is true,, but NOT both giving the Boolean Expression of: ( Q = (A and NOT B) or (NOT A and, B) )., , b) EX-NOR (Exclusive NOR) Gate, For a 2-input Ex-NOR gate, the output Q is true if BOTH input A and input B are the, same, either true or false, giving the Boolean Expression of: ( Q = (A and B) or (NOT A, and NOT B) )., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 14
Page 15 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , Summary of 2-input Logic Gates, The following Truth Table compares the logical functions of the 2-input logic gates above., , 5. TYPES OF SOFTWARE, There are 3 types of software, they are, i., ii., iii., , Application software, System software, Utility software, , i. Application software:, , , It is a group of program designed to accomplish a single task or a group of related tasks, Ex: Power point, MS word etc, , ii. System software:, , , , , It is a background software that enables the application software to interact with each, other, It acts as interface between hardware and user applicationEx: windows XP, windows 7, etc, , iii. Utility software:, , , , An application software that assist system software in doing their work is called utility, software, Ex: Antivirus software, backup software, etc, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 15
Page 16 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , 5.1 System Software and Utility Software, System software, System Software maintains the, system resources and gives the path, for application software to run., , Utility software, Utility software refers to software, programs that add functionally to, program that add functionality to, computer and helps to perform in, better way, , System Software, purpose software, , general, , Utility software mainly focuses on, how computer infrastructure such as, hardware,, operating, system,, software etc, operates, , System software is difficult to, design, , Utility software easier to build than, system software, , System Software has fast speed., , Utility software depends on the, specifications of the system., , is, , a, , Without system software, system, cannot run, , System Software can be either free, or paid if downloaded from web., Example of system software are, operating system etc, , Utility software can be downloaded, either from web or comes preinstalled, Utility Software is mostly free to, install in computer., Examples of utility software are:, Avast antivirus, disk tools, backup, software etc., , 6. COMPUTER LANGUAGES, There are 3 categories of computer languages:, i. Machine level language, ii. Assembly level language, iii. High level language, , 6.1 Machine level language, This is the only language that the computer understands without using a translation, program, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 16
Page 17 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , Normally written as strings of binary 1’s and 0’s, A typical machine language instruction format, , OPCODE tells the computer which operation to perform from the instruction set of the, computer, OPERAND tells the address of the data on which the operation is to be performed, Sample machine language program, , Advantages of machine language:, It can be executed very fast, Disadvantages of machine language:, Machine dependent, Difficult to program, Error prone, Difficult to modify, , 6.2 Assembly level language, It overcomes the limitations of machine language programming by, Using alphanumeric mnemonic codes instead o-f numeric codes for the, instructions in the instruction set, Ex: using ADD instead of 1110(binary) or 14(decimal) for instruction to add, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 17
Page 18 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , Allowing storage locations to be represented in the form of alphanumeric address, instead of numeric addresses, Ex: representing memory locations 1000, 1001, and 1002 as FRST, SCND, and, ANSR respectively, , Providing pseudo-instructions that are used for instructing the system how we, want the program to be assembled inside the computer’s memory, An example program of assembly language as shown below, , Advantages of assembly language:, Easier to understand and use, Easier to locate and correct errors, Easier to modify, No worry about address, Easily relocatable, Disadvantages of assembly language:, Machine dependent, Knowledge of hardware required, Machine level coding, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 18
Page 19 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , NOTE: Equivalent machine language program for the above assembly language program, , 6.3 High level language, Machine independent, Do not require programmers to know anything about the internal structure of computer, on which high-level language programs will be executed, Deal with high-level coding, Enabling the programmers to write instructions using English words and familiar, mathematical symbols and expressions, Examples: c, c++, java, etc, Advantages of High-level language:, Machine independent, Easier to learn and use, Fewer errors during program development, Lower program preparation cost, Better documentation, Easier to maintain, Disadvantages of High-level language, Lower execution efficiency, Less flexibility to control the computer’s CPU, memory and register, , 7. TRANSLATOR PROGRAMS, 7.1 Assembler, Software that translates as assembly language program into an equivalent machine, language program of computer, Arpitha K, Dept. of CS, , Mandya University, Mandya, , 19
Page 20 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , It converts the source program into object program. Here the source program is assembly, language program and the object program is machine language program, It is a one-to-one correspondence, , 7.2 Interpreter, Interpreter is a high-level language translator, It takes one statement of a high-level language program, translates it into machine, language instructions, Then immediately executes the resulting machine language instructions, Compiler simply translates the entire source program into an object program and is not, involved in its execution, It translates and executes statement-by-statement, , 7.3 Compiler, Compiler is a translator program that translate a high level language program into, machine language program, It compiles a set of machine language instructions for every program instruction in a, high-level language, It converts source program into object program, It is a one-to-many correspondence, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 20
Page 21 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , The below figure illustrates the requirement of a separate compiler for each high-level, language supported by a computer, , 8. PLANNING A COMPUTER PROGRAM, 8.1 Algorithm, The word Algorithm means “a process or set of rules to be followed in calculations or, other problem-solving operations”., Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a, work is to be executed upon in order to get the expected results., In order to write an algorithm, following things are needed as a pre-requisite:, The problem that is to be solved by this algorithm., The constraints of the problem that must be considered while solving the, problem., The input to be taken to solve the problem., The output to be expected when the problem is solved., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 21
Page 22 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , The solution to this problem, in the given constraints., Characteristics of algorithm:, Clear and Unambiguous: Algorithm should be clear and unambiguous. Each of, its steps should be clear in all aspects and must lead to only one meaning., Well-Defined Inputs: If an algorithm says to take inputs, it should be welldefined inputs., Well-Defined Outputs: The algorithm must clearly define what output will be, yielded and it should be well-defined as well., Finite-ness: The algorithm must be finite, i.e. it should not end up in an infinite, loops or similar., Feasible: The algorithm must be simple, generic and practical, such that it can, be executed upon will the available resources. It must not contain some future, technology, or anything., Language Independent: The Algorithm designed must be languageindependent, i.e. it must be just plain instructions that can be implemented in, any language, and yet the output will be same, as expected., Advantages of Algorithms:, , , , , It is easy to understand., Algorithm is a step-wise representation of a solution to a given problem., In Algorithm the problem is broken down into smaller pieces or steps hence, it, is easier for the programmer to convert it into an actual program., , Disadvantages of Algorithms:, , , , Writing an algorithm takes a long time so it is time-consuming., Branching and looping statements are difficult to show in Algorithms., , Example: Design an algorithm to add two numbers and display the result., Step 1 – START, Step 2 − declare three integers a, b & c, Step 3 − define values of a & b, Step 4 − add values of a & b, Step 5 − store output of step 4 to c, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 22
Page 23 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , Step 6 − print c, Step 7 − STOP, , 8.2 Flowchart, Flowchart is a pictorial representation of an algorithm, It uses symbols (boxes of different shapes) that have standardized meanings to denote, different types of instructions, Actual instructions are written within the boxes, Boxes are connected by solid lines having arrow marks to indicate the exact sequence in, which the instructions are to be executed, Process of drawing a flowchart for an algorithm is called flowcharting, , Advantages of flowchart:, Better communication, Proper program documentation, Efficient coding, Systematic debugging, Systematic testing, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 23
Page 24 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , Disadvantages of flowchart:, Flowcharts are very time consuming and laborious to draw (especially for large, complex problems), Redrawing a flowchart for modifications is a tedious task, There are no standards determining the amount of detail that should be included, in a flowchart, Example: to read radius of a circle and to find area and circumference, , 8.3 Pseudo code, Consists of natural language-like statements that precisely describe the steps of an, algorithm or program, Statements describe actions, Focuses on the logic of the algorithm or program, Avoids language-specific elements, Written at a level so that the desired programming code can be generated almost, automatically from each statement, Advantages of Pseudo code:, Acts as a bridge between the program and the algorithm or flowchart., It allows the designer to focus on main logic without being distracted by, programming languages syntax., , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 24
Page 25 :
I BSc, , Computer Fundamentals and Programming in C, , UNIT 1, , Since it is language independent, it can be translated to any computer language, code., It allows designer to express logic in plain natural language., It is easier to write actual code using pseudo code., Unlike algorithms, pseudo codes are concise so pseudo codes are more readable, and easier to modify., Disadvantages of pseudo code:, There are no accepted standards for writing pseudo codes and designer use their, own style while writing pseudo codes., Pseudo code cannot be compiled and executed so its correctness cannot be, verified by using computers., , Pseudo code Example: Express an algorithm to get two numbers from the user (dividend, and divisor), testing to make sure that the divisor number is not zero, and displaying their, quotient using pseudo code, 1. Declare variables: dividend, divisor, and quotient, 2. Prompt user to enter dividend and divisor, 3. Get dividend and divisor, 4. IF divisor is equal to zero, THEN, 4.1. DO, 4.1.1. Display error message, “divisor must be non-zero”, 4.1.2. Prompt user to enter divisor, 4.1.3. Get divisor, 4.2. WHILE divisor is equal to zero, 5. ENDIF, 6. Display dividend and divisor, 7. Calculate quotient as dividend/divisor, 8. Display quotient, , Arpitha K, Dept. of CS, , Mandya University, Mandya, , 25