Download presentation
1
GE6151 COMPUTER PROGRAMMING
2
GE6151 COMPUTER PROGRAMMING
UNIT I INTRODUCTION Generation and Classification of Computers- Basic Organization of a Computer –Number System – Binary – Decimal – Conversion – Problems. Need for logical analysis and thinking – Algorithm –Pseudo code – Flow Chart. UNIT II C PROGRAMMING BASICS Problem formulation – Problem Solving - Introduction to ‘ C’ programming –fundamentals – structure of a ‘C’ program – compilation and linking processes – Constants, Variables – Data Types – Expressions using operators in ‘C’ – Managing Input and Output operations – Decision Making and Branching – Looping statements – solving simple scientific and statistical problems. UNIT III ARRAYS AND STRINGS Arrays – Initialization – Declaration – One dimensional and Two dimensional arrays. String- String operations – String Arrays. Simple programs- sorting- searching – matrix operations. UNIT IV FUNCTIONS AND POINTERS Function – definition of function – Declaration of function – Pass by value – Pass by reference – Recursion – Pointers - Definition – Initialization – Pointers arithmetic – Pointers and arrays- Example Problems. UNIT V STRUCTURES AND UNIONS Introduction – need for structure data type – structure definition – Structure declaration – Structure within a structure - Union - Programs using structures and Unions – Storage classes, Pre-processor directives.
3
UNIT I INTRODUCTION Generation and Classification of Computers- Basic Organization of a Computer –Number System – Binary – Decimal – Conversion – Problems. Need for logical analysis and thinking – Algorithm –Pseudo code – Flow Chart.
4
INTRODUCTION
5
INTRODUCTION Early days people use fingers for computing purpose.
As years go, the computing needs also grew. This leads to the invention of calculators and computers. The term computer is derived from the word compute. The word compute means to calculate
6
Definition A Computer is an electronic machine that accepts data from the user, processes the data by performing calculations and operations on it, and generates the desired output results. Computer performs both simple and complex operations, with speed and accuracy. COMPUTER INPUT OUTPUT
7
Definition 1.”Computer is an electronic Device that is used for performing calculations and controlling operations that can be expressed either in logical or numerical terms”. 2.”Computer is an electronic device which automatically accepts and stores input data process them and produce the desired result”. 3.“Computer may be defined as an electronic device, that operates upon information or data”.
8
Basic functions or operations
Input Processing Output Storing Controlling
9
Applications of computer
Business Industry Home Education Printing & publishing Entertainment etc.,
10
CHARACTERISTICS OF COMPUTER
Speed Accuracy Diligence Versatility Resource sharing Storage
11
CHAPTER 1 Generation and Classification of Computers
12
Generations of Computers (Cont)
First Generation Computers: These computers were vacuum tube based machines. They used magnetic drums for memory. Input were fed into the computer using Punched cards The size of these computers were very large and it produce more heat. They lacked in versatility and speed. They were more expensive.
13
Figure . Vacuum tube
14
Generations of Computers (Cont)
Second Generation Computers Here the Transistor replaced the bulky vacuum tubes. Transistors are smaller than vacuum tubes and have higher operating speed. Thus the size of the computer got reduced considerably. Manufacturing cost was also very low. Generations of Computers (Cont)
15
Fig. Transistors
16
Generations of Computers (Cont)
Third Generation Computers These computers were based on Integrated Circuits (ICs) Technology. A single IC has many transistors, registers and capacitors built on a single thin slice of silicon. So that the size of the computer got further reduced. These Computers were small in size, low cost, large memory and processing speed is very high.
17
Fig .IC CHIPS
18
Generations of Computers (Cont)
Fourth Generation Computers It uses large scale Integrated Circuits (LSIC) built on a single silicon chip called microprocessors . Later very large scale Integrated Circuits (VLSIC) replaced LSICs These computers are called microcomputers. Thus the size of the computer got reduced. The personal computer (PC) are comes under the Fourth Generation.
19
Fig. Microprocessors
20
Generations of Computers (Cont)
Fifth Generation Computer The speed is extremely high in fifth generation computer. The concept of Artificial intelligence has been introduced to allow the computer to take its own decision. It is still in a developmental stage .
21
Classification of Computer
22
Classification of Computer
The digital computers that are available nowadays vary in their sizes and types. The computers are broadly classified into four categories (Figure 1.8) based on their size and type: (1) Microcomputers (2) Minicomputers (3) Mainframe computers (4) Supercomputer
23
Figure 1.8 . Classification of computers based on size and type
Fast Expensive Complex Large Slow Cheap Simple Small Figure Classification of computers based on size and type
24
Microcomputer Microcomputers are small, low cost and single-user digital computer consist of CPU,input unit, output unit, storage unit and the software. stand alone machines-can be connected together to create a network Example: IBM PC based on Pentium microprocessor and Apple Macintosh Microcomputers include desktop computers notebook computers or laptop, tablet computer handheld computer smart phones and netbook
25
Figure 1.9 Microcomputers
Netbook Laptop PC Figure 1.9 Microcomputers Smart phone Tablet PDA
26
Mini Computer This is designed to support more than one user at a time
It possesses large storage capacity and operates at a higher speed This type of computer is generally used for processing large volume of data in an organization. Eg: Servers in Local Area Networks (LAN).
27
Mini computer
28
Mainframe Computers They operate at very high speed, having very large storage capacity and can handle the work load of many users They are generally used in centralized databases. Mainframe computer
29
Supercomputers They are the fastest and most expensive machines
They have high processing speed compared to other computers They have also multiprocessing technique Supercomputers are mainly being used for whether forecasting, biomedical research, Space Research and other areas of science and technology
30
Supercomputer
31
CHAPTER2 BASIC ORGANISATION OF COMPUTER
32
Basic organization of computer
CONTROL INPUT MEMORY OUTPUT ALU
33
Basic organization of computer
INPUT The input unit is used to information or instruction to the computer. It accept the information or instruction from user or from some where else. Convert it to a computer understandable form and send it to the computer. Eg:Keyboard,mouse,Joystick,MICR, etc,.
34
Basic organization of computer (cont)
CENTRAL PROCESSING UNIT (CPU) It is the heart of the computer. It performs all operations. It contains the followings CONTROL UNIT ALU MEMORY
35
Basic organization of computer (cont)
CONTROL UNIT It controls all other units in the computer. It directs the sequence in which operations to be performed. It also controls the flow of data between various units.
36
Basic organization of computer (cont)
MEMORY UNIT Place for holding the information. Types 1.Primary 2.Secondary Primary memory is used to store temporary data. Eg:RAM,ROM etc,. Secondary memory is used to store information permanently. Eg:Hard disk.
37
Basic organization of computer
OUTPUT The output unit is used to display the result of the process. Eg:Monitor,printer,speakers, etc,.
38
CHAPTER 3 NUMBER SYSTEM
39
Data Representation The data stored in the computer may be of different kinds, as follows: Numeric data (0, 1, 2, ... , 9) Alphabetic data (A, B, C, ... , Z) Alphanumeric data-Combination of any of the symbols-(A, B, C .. Z), (0,1..9),or special characters (+,-, Blank), etc. All kinds of data, be it alphabets, numbers, symbols, sound data or video data, is represented in terms of 0s and 1s, in the computer. Each symbol is represented as a unique combination of 0s and 1s.
40
Number system A number system in base r or radix r uses unique symbols for r digits. One or more digits are combined to get a number. base of the number decides the valid digits that are used to make a number. In a number, the position of digit starts from right-hand side of the number. Rightmost digit has position 0, the next digit on its left has position 1, and so on. The digits of a number have two kinds of values: Face value Position value The face value of a digit is the digit located at that position. For example, in decimal number 52, face value at position 0 is 2 and face value at position 1 is 5.
41
The position value of a digit is (base Position)
The position value of a digit is (base Position). For example, in decimal number 52, the position value of digit 2 is 10° and the position value of digit 5 is 101. Decimal numbers have a base of 10. The number is calculated as the sum of, face value * base position, of each of the digits For decimal number 52, the number is 5* *10° = = 52 In computers, we concerned with four kinds of number systems, as follows: Decimal Number System -Base 10 Binary Number System -Base 2 Octal Number System - Base 8 Hexadecimal Number System -Base 16
42
Number System Number Base B => B symbols
Base 16 (Hexa) : 0, 1,……9, A ,…, E, F Base 10 (Decimal) : 0, 1, 2,……, 7, 8, 9 Base 8(Octal) : 0, 1, 2, 3, 4, 5, 6, 7 Base 2 (Binary) : 0, 1
44
Number System (cont) Number representation:
d31d d2d1d0 is a 32 digit number value = d31x B31 + d30 x B d2 x B2 + d1 x B1 + d0 x B0
45
Decimal Numbers: Base 10 Base or Radix is 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Example: = 4x x x100 = = 412
46
Binary Numbers: Base 2 Base or Radix is 2 Digits: 0, 1 Example:
1012 = 1x22 + 0x21 + 1x20 = = 5
47
Octal Numbers: Base 8 Base or Radix is 8
Digits: 0, 1, 2, 3, 4, 5, 6, 7 Example: 1238 = 1x82 + 2x81 + 3x80 = = 83
48
Hexadecimal Numbers: Base 16
Digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F: A 10 B 11 C 12 D 13 E 14 F 15 Example: 1216 = 1x x160 = 16 +2 = 18 Hexadecimal Numbers: Base 16
50
Conversions Decimal to Base N Base N to Decimal
Successive Division by N (Remainder Method) Multiplication with power of N
51
Decimal to Binary
52
Conversion of 2510 to Binary
2 25 1 - 1 2510=110012
53
Binary to decimal conversion
11001 1X20 = 1 0X21 = 0 0X22 = 0 1X23 = 8 1X24 = 16 2510
54
Decimal to Octal
55
Conversion of to Octal 8 125 12510=1758
56
Octal to decimal conversion
175 5X80 = 5 7X81 = 56 1X82 = 64 125 1758 = 12510
57
Conversion of 8410 to Octal 8 84 8410=1248
58
Octal to decimal conversion
124 4X80 = 4 2X81 = 16 1X82 = 64 84 1248 = 8410
59
Decimal to Hexa
60
Conversion of 45010 to Hexadecimal
45010=1C216
61
Hexa to decimal conversion
450 1C216 = 45010
62
Conversion of 38510 to Hexadecimal
38510=18116
63
Hexa to decimal conversion
181 1X160 = 8X161 = 1X162 = 385 18116 =
64
Other Conversions BINARYOCTAL BINARYHEXA OCTALHEXA etc,.
65
BINARYOCTAL OCTAL – BASE 8 = 23 3 DIGIT BINARY NUMBER Example: OCTAL 110012=318
66
Example: OCTAL =1638
67
BINARYHEXA HEXA – BASE 16 = 24 4 DIGIT BINARY NUMBER Example: HEXA 110012=1916
68
Example: OCTAL =1638
69
OCTALHEXA OCTALBINARYHEXA Example:318 HEXA 318=1916
70
HEXA OCTAL Example: 1BD OCTAL B D 1BD = 6758
71
Conversion of 25.12510 to Binary
2 25 1 - 1 2510=110012
72
0.125 X 2 = 0.250 0.250 X 2 = 0.5 0.5 X 2 = 1.0 =
73
Binary to decimal conversion
1X2-3 = 0X2-2 = 0 0X2-1 = 0 1X20 = 0X21 = 0X22 = 0 1X23 = 1X24 =
74
Conversion of to Octal 8 84 8410=1248
75
0.250 X 8 = 2.000 =
76
Octal to decimal conversion
124.2 2X8-1 = 4X80 = 1 2X81 = 0 1X82 = 0
77
ASSIGNMENT
78
DECIMAL TO BINARY 43 79 107 241 476
79
DECIMAL TO OCTAL 39 152 284 758 2534
80
DECIMAL TO HEXA 75 826 3128 7359 4756
81
DECIMAL TO OTHER 63 BASE4 279 BASE6 161 BASE7
82
BINARY OCTAL,HEXA
83
OCTAL HEXA 473 1235 724 5774 4625
84
BASE2 OCTAL HEXA
85
NEED FOR LOGICAL ANALYSIS AND THINKING
CHAPTER 4 NEED FOR LOGICAL ANALYSIS AND THINKING
86
NEED FOR LOGICAL ANALYSIS AND THINKING
Logical thinking is the process of understanding something; we put together our judgment, reasoning, and other forms of thinking to reflect the reality of knowledge. Logics and reasoning are also known as concepts of understanding something logically. It is recognized as a structure of thinking and the analysis of the appearance and development of something. Only through logical thinking, we can achieve the specific goals or targets. It is the advanced stage of understanding something, different thoughts may apply on the same problem to get the specific task to be done. It is characterized by abstract, emotional, material, and analytical thinking. When finalizing the goal or target of something, we have put together our judgment and reasoning, indirectly reflecting reality.
87
Our brain is powerful in logical thinking, this enables us to scientifically expose the essence of something in an abstract and logical way with our consciousness. Logic is the basic form of the concept, judgment and reasoning. Logical ways of thinking are mainly induction, deduction, analysis and synthesis, from abstract to the concrete. Logic is also known as abstract thinking, a higher form of thinking. Its characteristics are abstract concepts, judgment and reasoning as basic forms of thinking, such as analysis, synthesis, generalization, and so on. Thereby, it helps to expose the essence of the characteristics and laws of the things that we observe. The same logic applies to in computer programming.
88
ALGORITHM
89
ALGORITHM Algorithm is an ordered sequence of finite, well defined, unambiguous instructions for completing a task. Algorithm is an English-like representation of the logic which is used to solve the problem. It is a step-by-step procedure for solving a task or a problem. The steps must be ordered, unambiguous and finite in number. For accomplishing a particular task, different algorithms can be written. The different algorithms differ in their requirements of time and space. The programmer selects the best-suited algorithm for the given task to be solved.
90
Let's now look at two simple algorithms to find the greatest among three numbers, as follows:
Algorithm to find the greatest among three numbers: ALGORITHM 1 Step 1: Start Step 2: Read the three numbers A, B, C Step 3: Compare A and B. If A is greater perform step 4 else perform step 5. Step 4: Compare A and C. If A is greater, output "A is greatest" else output "C is greatest". Perform step 6. Step 5: Compare Band C. If B is greater, output "B is greatest" else output "C is greatest". Step 6: Stop
91
ALGORITHM 2 Step 7: Start Step 8: Read the three numbers A, B, C Step 9: Compare A and B. If A is greater, store A in MAX, else store B in MAX. Step 10: Compare MAX and C. If MAX is greater, output "MAX is greatest" else output "C is greatest". Step 11: Stop Both the algorithms accomplish the same goal, but in different ways. The programmer selects the algorithm based on the advantages and disadvantages of each algorithm. For example, the first algorithm has more number of comparisons, whereas in the second algorithm an additional variable MAX is required.
92
FLOWCHART
93
FLOWCHART A flowchart is a diagrammatic representation of the logic for solving a task. drawn using boxes of different shapes with lines connecting them to show the flow of control. The purpose of drawing a flowchart is to make the logic of the program clearer in a visual form. There is a famous saying "A photograph is equivalent to thousand words". The same can be said of flowchart. The logic of the program is communicated in a much better way Since it is a diagrammatic representation-forms a common medium of communication.
94
Flowchart Symbols
95
Control structures in flowchart
Sequence Selection Control structures in flowchart
97
Examples of flowchart The first flowchart computes the product of any two numbers and gives the result. flowchart is a simple sequence of steps to be performed in a sequential order. The second flowchart compares three numbers and finds the maximum of the three numbers. This flowchart uses selection. In this flowchart, decision is taken based upon a condition, which decides the next path to be followed, i.e. If A is greater than B the true (Yes) path is followed else the false (No) path is followed. Another decision again made while comparing MAX with C.
98
3. The third flowchart finds the sum of first 100 integers
3. The third flowchart finds the sum of first 100 integers. Here, iteration (loop) is formed so that some steps are executed repetitively until they fulfill some condition exit from the repetition. In the decision box, the value of I is compared with 100. If false (No), a loop is created which breaks when the condition becomes true (Yes). Flowcharts have their own benefits; however, they have some limitations too. A com and long flowchart may run into multiple pages, which becomes difficult to understand follow. Moreover, updating a flowchart with the changing requirements is a challenging job.
99
PSEUDO CODE
100
Pseudo code Pseudo code consists of short, readable and formally-styled English language used for explaining an algorithm. Pseudo code does not include details like variable declarations, subroutines Pseudo code is a short-hand way of describing a computer program. Using pseudo code, it is easier for a programmer or a non-programmer to understand the general working of the program, since it is not based on any programming language. It is used to give a sketch of the structure of the program, before the actual coding. It uses the structured constructs of the programming language but is not machine readable Pseudo code cannot be compiled or executed
101
Preparing a Pseudo Code
1.Pseudo code is written using structured English. 2.In a pseudo code, some terms are commonly used to represent the various actions. Input (INPUT, GET, READ) output (OUTPUT, PRINT, DISPLAY) Calculations (COMPUTE, CALCULATE) incrementing (INCREMENT) ADD, SUBTRACT, INITIALIZE used for addition, subtraction, and initialization, respectively.
102
Figure 2.5 shows the different pseudo code structures.
The sequence structure is simply a sequence of steps to be executed in linear order. There are two main selection constructs if-statement case statement In the if-statement, if the condition is true then the THEN part is executed otherwise the ELSE part is executed. There can be variations of the if-statement also, like there may not be any ELSE part or there may be nested ifs. The case statement is used where there are a number of conditions to be checked. In a case statement, depending on the value of the expression, one of the conditions is true, for which the corresponding statements are executed. If no match for the expression occurs, then the OTHERS option which is also the default option, is executed.
103
Control structures for pseudo code
104
Examples of pseudo code
105
THANK YOU
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.