Itps All Units PDF
Document Details
Uploaded by HilariousEpitaph
University Institute of Engineering
Tags
Related
Summary
This document is a set of lecture notes on introduction to problem-solving via programming.
Full Transcript
UNIVERSITY INSTITUTE OF ENGINEERING DEPARTMENT- ACADEMIC UNITS FIRST YEAR ENGINEERING PROGRAMMES Subject Name : Introduction to Problem Solving Subject Code: 24CSH-101 Introduction to computers and programming DISCOVER. LEARN. EMPOW...
UNIVERSITY INSTITUTE OF ENGINEERING DEPARTMENT- ACADEMIC UNITS FIRST YEAR ENGINEERING PROGRAMMES Subject Name : Introduction to Problem Solving Subject Code: 24CSH-101 Introduction to computers and programming DISCOVER. LEARN. EMPOWER Introduction to Problem Solving Course Objectives The course aims to provide exposure to problem- solving through programming. The course aims to raise the programming skills of students via logic building capability. With knowledge of C programming language, students would be able to model real world problems. 2 Course Outcomes CO Course Outcome Number CO1 Remember the concepts related to fundamentals of C language, draw flowcharts and write algorithm/pseudocode. CO2 Understand the way of execution and debug programs in C language. CO3 Apply various constructs, loops, functions to solve mathematical and scientific problem. CO4 Analyze the dynamic behavior of memory by the use of pointers. CO5 Design and develop modular programs for real world problems using control structure and selection structure. 3 ASSESSMENT PATTERN The performance of students is evaluated as follows: Theory Practical Continuous Internal Semester End Continuous Internal Semester End Components Assessment (CAE) Examination (SEE) Assessment (CAE) Examination (SEE) Marks 40 60 60 40 Total Marks 100 100 4 What ?? Electronic device computers are electronic devices that accept data (input), process that data, produce output, and store (storage) the results. Why?? Memory is just like a human brain. It is used to store data and Make life simple instructions. Computer memory is If you do not have a sufficient amount of RAM the storage space in the computer, than your CPU has to work much, much harder where data is to be processed and to transfer data, which severally damages instructions required for the computer's performance. Random processing are stored. access memory also helps your system support software. 5 Basic Applications of Computer Home. Computers are used at homes for several purposes like online bill payment, watching movies or shows at home, home tutoring, social media access, playing games, internet access, etc. Medical Field. Entertainment. Industry. Education. Government. Banking. Business. 6 Space for visual (size 24) CONTENTS Introduction to computer Internal components of CPU Basic block diagram and functions of various components of computer Memory Memory layout of C program 7 What is a Computer? A computer is an electronic device used to store and process information. It plays a major role in our lives. You use computers in education and research. You also use them for broadcasting news, receiving and sending messages to family and friends, making presentations, maintaining official and personal records, making weather forecasts, and for various other business and recreation activities. By using computers, you save a lot of time, effort, and money. 8 Functions of Computers A computer is an electronic device that accepts data from the user, processes it, produces results, displays them to the users, and stores the results for future usage. Functions: Receiving Input Data is fed into computer through various input devices like keyboard, mouse, digital pens, etc. Input can also be fed through devices like CD-ROM, pen drive, scanner, etc. Processing the information Operations on the input data are carried out based on the instructions provided in the programs. Storing the information After processing, the information gets stored in the primary or secondary storage area. Producing output The processed information and other details are communicated to the outside world through output devices like monitor, printer, etc. Data is a collection of unorganized facts & figures and does not provide any further information regarding patterns, context, etc. Hence data means "unstructured facts and figures". Information is a structured data i.e. organized meaningful and processed data. To process the data and convert into information, a computer is used. 9 Computer Characteristics : Speed A computer works with much higher speed and accuracy compared to humans while performing mathematical calculations. Computers can process millions (1,000,000) of instructions per second. The time taken by computers for their operations is microseconds and nanoseconds. Accuracy Computers perform calculations with 100% accuracy. Errors may occur due to data inconsistency or inaccuracy. Versatility Versatility refers to the capability of a computer to perform different kinds of works with same accuracy and efficiency. Reliability A computer is reliable as it gives consistent result for similar set of data i.e., if we give same set of input any number of times, we will get the same result. Automation Computer performs all the tasks automatically i.e. it performs tasks without manual intervention. Memory A computer has built-in memory called primary memory where it stores data. Secondary storage are removable devices such as CDs, pen drives, etc., which are also used to store data. 10 Block Diagram of Computer 11 Input Devices The user provides the set of instruction or data to the computer system with the help of input devices such as the keyboard, mouse, scanner, etc. There are some important features of input devices which are given below: The input device performs like the connection between the outside world and computer system. The input devices receive or accept the data or instruction from the user These devices convert the data or instruction into the machine- readable form for further processing. 12 13 Memory Primary Memory Secondary Memory Cache Memory 14 Primary Memory: Primary memory is computer main memory that is accessed directly by the CPU. This includes several types of memory, RAM & ROM 15 Secondary memory We can store the data and programs on a long-term basis in the secondary memory. The hard disks and the optical disks are the common secondary devices. It is slow and cheap memory as compare to primary memory. This memory is not connected to the processor directly. It has a large capacity to store the data like 500 GB or 1 TB, The data and programs on the hard disk are organized into files, and the file is the collection of data on the disk. 16 Primary Vs Secondary memory Primary Memory Secondary Memory It is known as the main memory. It is known as the backup memory. Directly accessible by CPU Not directly accessible by CPU RAM is directly installed onto a The hard disk drive is connected to the motherboard motherboard by cable Usually volatile memory. It is a non-volatile memory, Data is lost in case power is switched off. Data is permanently stored even if power is switched off. It is the working memory of the It is used for storage of data in a computer, used for processing the data computer. Small size Large size A computer cannot run without the Computer may run without the primary memory. secondary memory. Faster than secondary memories. Slower than primary memories 17 Cache Memory Cache memory is a very high speed memory which can speed up the CPU. It acts as a buffer between the CPU and the main memory. It is used to hold most frequently used data, by the CPU Advantages Cache memory is faster than main memory. It stores data for temporary use. Disadvantages Cache memory has limited capacity. It is very expensive. 18 Central Processing Unit (CPU) The computer system is nothing without the CPU so, it is also known as the brain of computer. The CPU is an electronic hardware device which can perform different types of operations. The CPU contains two parts: Control Unit & Arithmetic logic unit Control Unit The control unit (CU) controls all the activities or operations which are performed inside the computer system Functions of this unit are − It is responsible for controlling the transfer of data and instructions among other units of a computer. It manages and coordinates all the units of the computer. It obtains the instructions from the main memory, interprets them, and directs the operation of the computer. It communicates with Input/output devices for transfer of data or results from storage. 19 ALU (Arithmetic Logic Unit) This unit consists of two subsections namely, Arithmetic Section Logic Section Arithmetic Section Function of arithmetic section is to perform arithmetic operations like addition, subtraction, multiplication, and division. All complex operations are done by making repetitive use of the above operations. Logic Section Function of logic section is to perform logic operations such as comparing, selecting, matching, and merging of data. 20 Output Devices The output devices produce or generate the desired result according to our input, such as a printer, monitor, etc. These devices convert the data into a human-readable form from binary code. The primary examples of output devices are a printer, projector, etc. These devices have various features which are given below: These devices receive or accept the data in the binary form. The output devices convert the binary code into the human-readable form. These devices produce the converted result and display to the user. 21 22 Summary In this lecture we have We have discussed about the discussed about functions of block diagram of computer, computer & computer how computer works. characteristics We have learnt about primary and secondary memory, RAM and ROM. 23 Frequently Asked question Q1 Differentiate RAM & ROM ? Ans. RAM and ROM are both types of computer memory. RAM is used to store computer programs and data that CPU needs in real time. RAM data is volatile and is erased once computer is switched off. ROM have prerecorded data and it is used to boot computer. RAM data is static and remains in the computer even if computer is switched off. Q2 Differentiate Primary & Secondary memory ? Ans. Primary memory is also called internal memory whereas Secondary memory is also known as a Backup memory or Auxiliary memory.... Primary memory data is directly accessed by the processing unit whereas Secondary memory data cannot be accessed directly by the processor Q3 Draw the Working of computer system? Ans. 24 Assessment Questions: 1. Any electronic holding place where data can be stored and retrieved later whenever required is ____________ a) memory b) drive c) disk d) circuit 2. Cache memory is the onboard storage. a) True b) False 3 The memory implemented using the semiconductor chips is _________ a) Cache b) Main c) Secondary d) Registers 4. Which of the following is independent of the address bus? a) Secondary memory b) Main memory c) Onboard memory d) Cache memory 25 5. ____________ is the raw material used as input and __________ is the processed data obtained as output of data processing. a) Data, Instructions b) Instructions, Program c) Data, Program d) Program, Code 6. Which of the following is not a characteristic of a computer? a) Diligence b) I.Q. c) Accuracy d) Versatility 7. The ‘heart’ of the processor which performs many different operations _____________ a) Arithmetic and logic unit b) Motherboard c) Control Unit d) Memory 8. ALU is the place where the actual executions of instructions take place during the processing operation. a) True b) False 26 REFERENCES Reference Books: Programming in C by Reema Thareja. Programming in ANSI C by E. Balaguruswamy, Tata McGraw Hill. Programming with C (Schaum's Outline Series) by Byron Gottfried Jitender Chhabra, Tata McGraw Hill. The C Programming Language by Brian W. Kernighan, Dennis Ritchie, Pearson education. Websites: https://www.tutorialandexample.com/block-diagram-of-a-computer/ https://www.tutorialspoint.com/computer_fundamentals/computer_memory.htm https://www.geeksforgeeks.org/memory-layout-of-c-program/ YouTube Links: https://www.youtube.com/watch?v=1owWbDQ5dJQ https://www.youtube.com/watch?v=v9e2gaUwKf4 https://www.youtube.com/watch?v=kpWG423uQIw 27 THANK YOU UNIVERSITY INSTITUTE OF ENGINEERING DEPARTMENT- ACADEMIC UNITS FIRST YEAR ENGINEERING PROGRAMMES Subject Name : Introduction to Problem Solving Subject Code: 24CSH-101 Problem Solving Phases DISCOVER. LEARN. EMPOWER Introduction to Problem Solving Course Objectives The course aims to provide exposure to problem- solving through programming. The course aims to raise the programming skills of students via logic building capability. With knowledge of C programming language, students would be able to model real world problems. 2 Course Outcomes CO Course Outcome Number CO1 Remember the concepts related to fundamentals of C language, draw flowcharts and write algorithm/pseudocode. CO2 Understand the way of execution and debug programs in C language. CO3 Apply various constructs, loops, functions to solve mathematical and scientific problem. CO4 Analyze the dynamic behavior of memory by the use of pointers. CO5 Design and develop modular programs for real world problems using control structure and selection structure. 3 ASSESSMENT PATTERN The performance of students is evaluated as follows: Theory Practical Continuous Internal Semester End Continuous Internal Semester End Components Assessment (CAE) Examination (SEE) Assessment (CAE) Examination (SEE) Marks 40 60 60 40 Total Marks 100 100 4 Space for visual (size 24) CONTENTS Introduction to problem solving Problem solving phases 5 What is a problem? The definition of a problem is something that has to be solved or an unpleasant or undesirable condition that needs to be corrected. An example of a problem is an algebra equation. An example of a problem is when it is raining and you don't have an umbrella. Everything happening in this world has its problems. This is because no system in this world has 100% efficiency. But this is not a big issue for the people who are prepared to deal with any kind of problem. The field that is heavily affected by the problems in the field of companies and organizations. 6 Problem Solving Problem-solving enables us to identify and exploit opportunities in the environment and exert (some level of) control over the future. Problem solving is the act of defining a problem; determining the cause of the problem; identifying, prioritizing, and selecting alternatives for a solution; and implementing a solution. Problem solving skills and the problem-solving process are a critical part of daily life both as individuals and organizations. 7 Characteristics of defining the problem Differentiate fact from opinion Specify underlying causes Consult each faction involved for information State the problem specifically Identify what standard or expectation is violated Determine in which process the problem lies Avoid trying to solve the problem without data 8 Phases of solving a problem Understanding the problem Making a plan of solution (i) Finding possible solutions Carrying out the plan (i) Choosing the best solution (ii) Implementing the solution. Looking back i.e. Verifying 9 Understanding the Problem Read the problem very carefully. Identify the functions that the solution (algorithm) should have. Identify the required output. Find a way to produce the required output. Draw a proper relationship between the input and output. Take all the necessary number of inputs. Avoid unnecessary inputs. Identify the correct number of the required input. 10 Making a plan of solution Postpone evaluating alternatives initially Include all involved individuals in the generating of alternatives Specify alternatives consistent with organizational goals Specify short- and long-term alternatives Brainstorm on others' ideas Seek alternatives that may solve the problem. 11 Carrying out the plan Identifying all the features of an ideal solution, including the constraints it has to meet Eliminating solutions which do not meet the constraints Evaluating the remaining solutions against the outcome required Assessing the risks associated with the 'best' solution Making the decision to implement this solution Implementing the solution This involves three separate stages: Planning and preparing to implement the solution Taking the appropriate action and monitoring its effects Reviewing the ultimate success of the action 12 Looking back This final stage requires an evaluation of the outcomes and results of the solution process: Did the option answer the questions we were working on? Did this process address the findings that came out of the assumptions? This process helps keep groups on track, and enables a thorough investigation of the problem and solution search. 13 Summary In this lecture we have We have discussed about the discussed about problem & phases of problem solving. problem solving We have learnt about problem solving solutions 14 Frequently Asked question Q1. What are the phases of problem solving? Ans: Understanding the problem Making a plan of solution (i) Finding possible solutions Carrying out the plan (i) Choosing the best solution (ii) Implementing the solution. Looking back i.e. Verifying 15 REFERENCES Reference Books Programming in C by Reema Thareja. Programming in ANSI C by E. Balaguruswamy, Tata McGraw Hill. Programming with C (Schaum's Outline Series) by Byron Gottfried Jitender Chhabra, Tata McGraw Hill. The C Programming Language by Brian W. Kernighan, Dennis Ritchie, Pearson education. Websites: https://www.thebalancecareers.com/problem-solving-skills-with-examples- 2063764 https://www.mindtools.com/pages/article/newTMC_00.htm https://asq.org/quality-resources/problem-solving YouTube Links: https://www.youtube.com/watch?v=klAE9ML0XLs https://www.youtube.com/watch?v=8BeXwhljq2g https://www.youtube.com/watch?v=-c5XAmA5Oc4 16 THANK YOU UNIVERSITY INSTITUTE OF ENGINEERING DEPARTMENT- ACADEMIC UNITS FIRST YEAR ENGINEERING PROGRAMMES Subject Name : Introduction to Problem Solving Subject Code: 24CSH-101 Flowcharts DISCOVER. LEARN. EMPOWER Introduction to Problem Solving Course Objectives The course aims to provide exposure to problem- solving through programming. The course aims to raise the programming skills of students via logic building capability. With knowledge of C programming language, students would be able to model real world problems. 2 Course Outcomes CO Course Outcome Number CO1 Remember the concepts related to fundamentals of C language, draw flowcharts and write algorithm/pseudocode. CO2 Understand the way of execution and debug programs in C language. CO3 Apply various constructs, loops, functions to solve mathematical and scientific problem. CO4 Analyze the dynamic behavior of memory by the use of pointers. CO5 Design and develop modular programs for real world problems using control structure and selection structure. 3 ASSESSMENT PATTERN The performance of students is evaluated as follows: Theory Practical Continuous Internal Semester End Continuous Internal Semester End Components Assessment (CAE) Examination (SEE) Assessment (CAE) Examination (SEE) Marks 40 60 60 40 Total Marks 100 100 4 What A flow chart is a graphical or symbolic representation of a process. Each step in the process is represented by a different symbol and contains a short description of the process step. The flow chart symbols are linked together with arrows showing the process flow direction. Why This diagrammatic representation illustrates a solution model to a given problem. Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields. 5 Uses of Flowchart: Planning a new project. Documenting a process. Modeling a business process. Managing workflow. Auditing a process. Mapping computer algorithms. Data management. Chemical and process engineering. 6 Space for visual (size 24) CONTENTS Introduction to Flowcharts Symbols used in flowcharts Example Flowcharts 7 FLOWCHART A flow chart is a graphical or symbolic representation of a process. Each step in the process is represented by a different symbol and contains a short description of the process step. It uses several geometrical figures to represent the operations, and arrows to show the direction of flow. The flow chart symbols are linked together with arrows showing the process flow direction. 8 Flowcharts Symbols: 9 10 IDEA OF FLOWCHART Oval shaped symbol is used to denote the start/end of program This symbol is used to show the I/O performed This symbol is used to show the process This symbol represents the point where decision is made This symbol is used to show the I/O performed Oval shaped symbol is used to denote the start/end of program 11 EXAMPLES OF FLOWCHART AND ALGORITHMS Example: Add 10 and 20 Start Initialize sum = 0 (PROCESS) Enter the numbers (I/O) Add them and store the result in sum (PROCESS) Print sum (I/O) Stop Figure 1.9 flowchart for addition of two numbers 12 EXAMPLE: CALCULATE INTEREST OF BANK DEPOSIT Algorithm: Step 1: Start Step 2: Read amount, Step 3: Read years, Step 4: Read rate, Step 5: Calculate the interest with formula Interest=Amount*Years*Rate/100 Step 6: Print interest Step 7: Stop Figure 1.10 flowchart to calculate interest rate 13 DETERMINE WHETHER THE NUMBER IS EVEN OR ODD Algorithm: Step 1: Start Step 2: Read number N, Step 3: Set remainder as N modulo 2, Step 4: If remainder is equal to 0 then number N is even, else number N is odd. Step 5: Print output. Step 6: End Figure 1.11 flowchart for even/odd 14 DETERMINE WHETHER TEMPERATURE IS ABOVE OR BELOW FREEZING POINT Algorithm: Step 1: Start Step 2: Input temperature, Step 3: If it is less than 32, then print "below freezing point", otherwise print "above freezing point“ Step 4: End Figure 1.12 flowchart to determine temperature 15 DETERMINE WHETHER STUDENT PASSED THE EXAM OR NOT Algorithm: Step 1: Start Step 2: Input grades of 4 courses M1, M2, M3 and M4, Step 3: Calculate the average grade with formula Grade=(M1+M2+M3+M4)/4 Step 4: If the average grade is less than 60, print "FAIL", else print "PASS". Step 5: End Figure 1.13 flowchart to print pass/fail 16 Print Hello World 10 times Start Initialize count = 0 (PROCESS) Print Hello World (I/O) Increment count by 1 (PROCESS) Is count < 10 (DECISION) if YES go to step 2 else Stop Stop Figure 1.14 flowchart to print hello 10 times 17 Key Differences Between Algorithm and Flowchart An algorithm involves a combination of sequential steps to interpret the logic of the solution. In contrast, a flowchart is the pictorial illustration of the algorithm. A flow chart is more understandable as compared to the algorithm. The algorithm is written in a language that can be perceived by humans. On the other hand, the flowchart is made up using different shapes and symbols. There are no stringent rules are implemented in the algorithms while the flowchart is abode by predefined rules. Errors and bugs are easily detected in the algorithm as compared to the flow charts. Flow charts are simple to create. On the contrary, the construction of the algorithm is complex. 18 ADVANTAGES OF FLOWCHART It is a convenient method of communication. It indicates very clearly just what is being done, where a program has logical complexities. A key to correct programming. It is an important tool for planning and designing a new system. It clearly indicates the role-played at each level. It saves the inconveniences in future and serves the purpose of documentation for a system. It provides an overview of the system and also demonstrates the relationship between various steps. Facilitates troubleshooting. It promotes logical accuracy. It makes sure that no logical path is left incomplete without any action being taken. 19 DISADVANTAGES The flowchart is a waste of time and slows down the process of software development. The flowchart is quite costly to produce and difficult to use and manage. Flowcharts are not meant for man to computer communication. Sometimes the Complex logic of the program logic is quite complicated to draw out on by using different defined shapes. In that case, flowchart becomes complex and clumsy. This will become a pain for the user, resulting in a waste of time and money trying to correct the problem If you need to modify or alternate the process then it will be very hard to do in the flowchart. Because either you will have to erase the end of the flowchart or start. 20 Summary In this lecture we have In this lecture we have learnt discussed about need and use how to design flowchart , how of flowcharts to use specific symbol. We have also discussed some advantages , disadvantages and applications of Flowcharts 21 Frequently Asked question Q1: What is a sub-process in a flowchart? Answer: Sometimes complex processes are broken down into smaller sub-processes for clarity. So a flowchart can point to a different sub process within its flow. The predefined process symbol is used to show such sub-processes. Q2: How are flowcharts used in computer programming? Answer: A computer program consists many processes and flows. Flowcharts are used to visualize the processes and make it understandable for nontechnical people. They are also used to visualize algorithms and comprehend pseudo code which is used in programming. Q3: Which online tools can I use to create flowcharts? Answer: There are numerous tools which you can find easily. Some of them are: Raptor, Visual Paradigm, Gliffy, and Creately 22 Q4: Draw the flowchart to represent the sum of two numbers. 23 Q5 Draw the flowchart to calculate profit and Loss. Answer: Flowchart –Calculate Profit and Loss The flowchart example below shows how profit and loss can be calculated. 24 Assessment Questions: 1. The symbol denotes ______ a) I/O b) Flow c) Terminal d) Decision 2. The box denotes? a) Decision b) Initiation c) Initialization d) I/O 3. Design a flowchart to check leap year 4. Design a flowchart to find sum of n natural numbers 5. Design a flowchart of Quadratic equation 25 Discussion forum. Students please have a look at this Medical Service Flowchart and try to improve it. 26 REFERENCES Reference Books: Programming in C by Reema Thareja. Programming in ANSI C by E. Balaguruswamy, Tata McGraw Hill. Programming with C (Schaum's Outline Series) by Byron Gottfried Jitender Chhabra, Tata McGraw Hill. The C Programming Language by Brian W. Kernighan, Dennis Ritchie, Pearson education. Websites: https://medium.com/@warren2lynch/a-comprehensive-guide-for- flowchart-over-50-examples-785d6dfdc380 https://www.geeksforgeeks.org/an-introduction-to-flowcharts/ https://www.programiz.com/article/flowchart-programming YouTube Links: Introduction to Creating Flowcharts: https://youtu.be/SWRDqTx8d4k Introduction to Flowchart Symbols: https://youtu.be/kxZJv56BxU8 27 THANK YOU UNIVERSITY INSTITUTE OF ENGINEERING DEPARTMENT- ACADEMIC UNITS FIRST YEAR ENGINEERING PROGRAMMES Subject Name : Introduction to Problem Solving Subject Code: 24CSH-101 Algorithm DISCOVER. LEARN. EMPOWER Introduction to Problem Solving Course Objectives The course aims to provide exposure to problem- solving through programming. The course aims to raise the programming skills of students via logic building capability. With knowledge of C programming language, students would be able to model real world problems. 2 Course Outcomes CO Course Outcome Number CO1 Remember the concepts related to fundamentals of C language, draw flowcharts and write algorithm/pseudocode. CO2 Understand the way of execution and debug programs in C language. CO3 Apply various constructs, loops, functions to solve mathematical and scientific problem. CO4 Analyze the dynamic behavior of memory by the use of pointers. CO5 Design and develop modular programs for real world problems using control structure and selection structure. 3 ASSESSMENT PATTERN The performance of students is evaluated as follows: Theory Practical Continuous Internal Semester End Continuous Internal Semester End Components Assessment (CAE) Examination (SEE) Assessment (CAE) Examination (SEE) Marks 40 60 60 40 Total Marks 100 100 4 What An algorithm is a set of instructions designed to perform a specific task, In Why computer programming, al Algorithms are a gorithms are often created very important topic in Computer as functions. These Science because they help functions serve as small software developers create programs that can be efficient and error free programs. referenced by a larger program 5 Space for visual (size 24) CONTENTS Introduction to C Programming Features of C programming Algorithms 6 Programming Language The language, through which user can interact with computer is known as computer language or programming language. 7 Types of Programming language: Machine language is the low level programming language. Machine language can only be represented by 0s and 1s, it is a collection of binary digits or bits that the computer reads and interprets directly In earlier when we have to create a picture or show data on the screen of the computer then it is very difficult to draw using only binary digits(0s and 1s). For example: To write 120 in the computer system its representation is 1111000. So it is very difficult to learn. To overcome this problem the assembly language is invented. 8 Assembly language is the more than low level and less than high-level language so it is intermediary language. Assembly languages use numbers, symbols, and abbreviations instead of 0s and 1s.For example: For addition, subtraction and multiplications it uses symbols likes Add, Sub and Mul, etc. High-level languages are designed to be used by the human operator or the programmer. They are referred to as "closer to humans." In other words, their programming style and context is easier to learn and implement than low-level languages Examples of high-level programming languages in active use today include Python, Visual Basic, Delphi, Perl, PHP, ECMAScript, Ruby, C#, Java and many others. 9 Language Translator: Job of Assembler: 10 Compiler & interpreter Compiler transforms code written in a high-level programming language into the machine code, at once, before program runs, whereas an Interpreter coverts each high-level program statement, one by one, into the machine code, during program run. Compiled code runs faster while interpreted code runs slower. 11 C language C is a structured programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programing language to write an operating system. Features of C language: 12 Structured programming language :C is a structured programming language in the sense that we can break the program into parts using functions. So, it is easy to understand and modify. Functions also provide code reusability. Portability: C language is lavishly portable as programs which are written in C language can run and compile on any system with either none or small changes. Fast and Efficient: Programs Written in C are efficient and fast because of its variety of data type and powerful operators. Mid-level programming language: As it is a middle-level language so it has the combined form of both, capabilities of assembly language and features of the high level language. Rich set of built-in Operators: It is a diversified language with a rich set of built-in operators which are used in writing complex or simplified C programs. 13 Libraries with rich functions: C provides a lot of inbuilt functions that make the development fast. Memory Management: It supports the feature of dynamic memory allocation. In C language, we can free the allocated memory at any time by calling the free() function. Pointer: C provides the feature of pointers. We can directly interact with the memory by using the pointers. Recursion: In C, we can call the function within the function. It provides code reusability for every function. Recursion enables us to use the approach of backtracking. Easy to Extend: Programs written in C language can be extended means when a program is already written in it then some more features and operations can be added into it. 14 ALGORITHM An algorithm is a series of instructions for carrying out an operation or solving a problem. It is important to write computer programs without any logical error to generate the proper output, so it is recommended that the programmer prepare a rough design to solve the problem by showing the steps involved in the program. This is called algorithm. In simple words, an algorithm is a step by step procedure to describe the solution of a particular problem. Let’s take a real-world example, a simple algorithm to make a coffee! So, what are the steps involved in making a Tea? Let’s write down all the steps one by one. 15 Characteristics of Algorithm Finiteness: Any algorithm should complete at one particular time and this is very important for any algorithm otherwise your algorithm will go in infinite state and it will not complete ever. Definiteness: Each algorithm should be clear and unambiguous. Effectiveness: Each line of an algorithm should be essentials. We should try to write in a simple way so it would be basic. Input: Every algorithm should take input it can be Zero or one or more. So according to the conditions user can use. Output: For any work some output should come, this is must otherwise there is no meaning of any work. In the same way, each algorithm should generate one or more output. Generality: The algorithm should be common for the set of input and requirements so the same algorithm can apply in multiple places according to the user’s requirements. 16 ALGORITHM TO MAKE TEA Step 1- Start Step 2-Take a cup and tea bag Step 3-Put the teabag in cup. Step 4-Fill the kettle with water. Step 5-Boil the water for few seconds Step 6-Pour some of the boiled water into the cup. Step 7-Add milk to the cup. Step 8-Add required sugar to the cup. Step 9- Stir the cup for few seconds and the tea is ready Step 10- Stop 17 Example: Add Two Numbers Step 1 Start Step 2 Accept or Read number1 Inputs Step 3 Accept or Read number2 Step 4 Add number1 and number2 and store the result in sum Process Sum=number1+number2 Step 5 Display sum Step 6 Stop Output 18 Example: Calculate area of Rectangle STEP 1 : Start STEP 2 : Read W of Rectangle STEP 3 : Read h of Rectangle STEP 4 : calculate area Area = w × h STEP 5 : Display Area STEP 6 : Stop 19 CALCULATE INTEREST OF BANK DEPOSIT Step 1: Start Step 2: Read Amount Step 3: Read Years Step 4: Read Rate Step 5: Calculate the interest with formula Interest=Amount*Years*Rate/100 Step 6: Display interest 20 DETERMINE WHETHER STUDENT PASSED THE EXAM OR NOT Step 1: Start Step 2: Read grades of 4 courses M1, M2, M3 and M4, Step 3: Calculate the average grade with formula "Grade=(M1+M2+M3+M4)/4" Step 4: If the average grade is less than 60, Display "FAIL", else Display "PASS". Step 5: Exit 21 DETERMINE WHETHER THE NUMBER IS EVEN OR ODD Step 2: Read Number N, Step 3: Set remainder = N modulo 2, Step 4: If remainder is equal to 0 then Goto step 5 else Goto step 6 Step 5: Display Number N is even Step 6: Display Number N is odd. Step 7: Stop 22 Display your name ( 1 time & 100 times) Step 1: Start Step 1: Start Step 2: Set counter=1 Step 2: Display “Aman” Step 3: Repeat steps 4 and 5 until Repetition of Step 3: Stop counter b goto step 4, otherwise goto step 5 Start 4 : if a > c goto step 6, otherwise goto step 8 Start 5 : if b > c goto step 7, otherwise goto step 8 Start 6 : Output "a is the largest", goto step 9 Start 7 : Output "b is the largest", goto step 9 Start 8 : Output " c is the largest", goto step 9 Start 9 : Stop 28 Assessment Questions: 1. The word ____________comes from the name of a Persian mathematician Abu Ja’far Mohammed ibn-i Musa al Khowarizmi. a) Flowchart b) Flow c) Algorithm d) Syntax 2. In computer science, algorithm refers to a special method usable by a computer for the solution to a problem. a) True b) False 3. This characteristic often draws the line between what is feasible and what is impossible. a) Performance b) System Evaluation c) Modularity d) Reliability 29 4. Which of the following is incorrect? Algorithms can be represented: a) as pseudo codes b) as syntax c) as programs d) as flowcharts 5. When an algorithm is written in the form of a programming language, it becomes a _________ a) Flowchart b) Program c) Pseudo code d) Syntax 6. Any algorithm is a program. a) True b) False 7 Design an algorithm to calculate percentage of a student for marks of 5 subjects. 8 Design an algorithm to check the given number is positive negative or zero 9 Design an algorithm to find maximum among 4 numbers 10 design an algorithm to check whether a person is eligible for vote or not. 11. Differentiate Middle level and high level language. 30 Discussion forum. Real life applications of algorithms, students please have a look at this video and mention your views , also add some new examples https://www.youtube.com/watch?v=CvSOaYi89B4 31 REFERENCES Reference Books: Programming in C by Reema Thareja. Programming in ANSI C by E. Balaguruswamy, Tata McGraw Hill. Programming with C (Schaum's Outline Series) by Byron Gottfried Jitender Chhabra, Tata McGraw Hill. The C Programming Language by Brian W. Kernighan, Dennis Ritchie, Pearson education. Websites: https://en.wikipedia.org/wiki/Algorithm https://fiftyexamples.readthedocs.io/en/latest/algorith ms.html https://study.com/academy/lesson/what-is-an- algorithm-definition-examples.html YouTube Links: What is an algorithm? https://youtu.be/6hfOvs8pY1k Characteristics of algorithm. https://youtu.be/FbYzBWdhMb0 32 THANK YOU UNIVERSITY INSTITUTE OF ENGINEERING DEPARTMENT- ACADEMIC UNITS FIRST YEAR ENGINEERING PROGRAMMES Subject Name : Introduction to Problem Solving Subject Code: 24CSH-101 Structure of C program DISCOVER. LEARN. EMPOWER Introduction to Problem Solving Course Objectives The course aims to provide exposure to problem- solving through programming. The course aims to raise the programming skills of students via logic building capability. With knowledge of C programming language, students would be able to model real world problems. 2 Course Outcomes CO Course Outcome Number CO1 Remember the concepts related to fundamentals of C language, draw flowcharts and write algorithm/pseudocode. CO2 Understand the way of execution and debug programs in C language. CO3 Apply various constructs, loops, functions to solve mathematical and scientific problem. CO4 Analyze the dynamic behavior of memory by the use of pointers. CO5 Design and develop modular programs for real world problems using control structure and selection structure. 3 ASSESSMENT PATTERN The performance of students is evaluated as follows: Theory Practical Continuous Internal Semester End Continuous Internal Semester End Components Assessment (CAE) Examination (SEE) Assessment (CAE) Examination (SEE) Marks 40 60 60 40 Total Marks 100 100 4 What is C ?? C is a structured programming language. It was initially developed by Why C?? Dennis Ritchie in the year Newer languages like java, python offer 1972. It was mainly more features than c programming developed as a system language but due to additional programing language to processing, their performance rate gets write an operating system. down effectively. C programming language as the been middle-level language provides programmers access to direct manipulation with the computer hardware but higher-level languages do not allow this. That’s the reasons C language is considered as the first choice to start learning programming languages. 5 CONTENTS Structure of C program Compilation and Execution process Program demonstration 6 Structure of C program Structure of C program is defined by set of rules called protocol, to be followed by programmer while writing C program. All C programs are having sections/parts which are mentioned here. 7 STRUCTURE OF C PROGRAM- EXAMPLE Sample text here (16) Figure 2.3. Program 1 (executed on Dev-C++ IDE) 8 STRUCTURE OF C PROGRAM- EXAMPLE Figure 2.4. Program 1 output (executed on Dev-C++ IDE) 9 Documentation Section The documentation section consists of a set of comment lines, giving the name of the program, the author and other details, which the programmer would like to use later. The comments can be written in two ways: a) Multi-line comment Ex: b) Single-line comment // This is a single-line comment // Author: Aman 10 Link Section The link section provides instructions to the compiler to link functions from the system library. If we want to access the functions stored in the library, it is necessary to tell the compiler about the files to be accessed. This is achieved by using the preprocessor directive #include as follows: #include where filename is the name of the library file that contains the required function definition. Preprocessor directives are placed at the beginning of the program. Some of the examples are: #include #include #include 11 Definition Section The definition section defines all symbolic constants. A #define is a preprocessor compiler directive and not a statement. Therefore #define lines should not end with a semicolon. Symbolic constants are usually written in uppercase so that they are easily distinguished from lowercase variable names. e.g. #define YEAR 2014 #define PI 3.14 Global Declaration Section There are some variables that are used in more than one function. Such variables are called global variables and are declared in the global declaration section. This section also declares all the user-defined functions. 12 main( ) Function Section Every C program must have one main( ) function section. This section contains two parts, declaration part and executable part. The declaration part declares all the variables used in the executable part. These two parts must appear between the opening and the closing braces. The program execution begins at the opening brace and ends at the closing brace. The closing brace of the main function section is the logical end of the program. All the statements in the declaration and executable parts end with a semicolon (;). 13 Subprogram Section The subprogram section contains all the user-defined functions that are called in the main functions. User-defined functions are generally placed immediately after the main function, although they may appear in any order. 14 Rules to write c program All C statements must end with semicolon. C is case-sensitive. That is, upper case and lower case characters are different. Generally the statements are typed in lowercase. C statement can be written in one line or it can split into multiple lines. Braces must always match upon pairs, i.e., every opening brace { must have a matching closing brace }. Every C program starts with main() function. 15 First example program: Documentation Pre-processor directive main function Main function body Statement 16 Need of compiler: 17 Compilation & Execution process File1.c File1.i File1.o or File1.obj File1.exe Final output 18 KEYWORDS IN C 19 Summary In this tutorial we have seen the structure of C program, We have discussed the how to design a c program importance of header files in a including preprocessor program , the definition of directives, global declaration, predefined functions is stored main function and some user in header files. defined functions. At the end we have seen the We have discussed about the live demonstration to design a compilation and execution code in C, Source code must be process, compiler translate the saved in Hello.c then c source code into machine converted into code. hello.ihello.objhello.exe Output 20 Frequently Asked question Q1 Differentiate compiler and interpreter. Compiler transforms code written in a high-level programming language into the machine code, at once, before program runs, whereas an Interpreter coverts each high-level program statement, one by one, into the machine code, during program run. Compiled code runs faster while interpreted code runs slower. Q2 what is the need of preprocessing ? The C preprocessor is the macro preprocessor for the C programming language. The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control. In many C implementations, it is a separate program invoked by the compiler as the first part of translation. 21 Assessment Questions: Q Choose the correct option Q3 Which of the following is type of an error: Q1 Role of Linker is: A) Syntax error A) Link with compiler B) Logic error B) Link with system libraries C) Data error C) Link with assembler D) All above D) generate output Q2 After compilation which file is created Q4 Correct documentation syntax is: A) file.c A) / hello world program / B) file.obj B) // hello world program C) file.exe C) / else return (number * factorial(number - 1)); } 7 1. We declare our recursive factorial function which takes an integer parameter and returns the factorial of this parameter. This function will call itself and decrease the number until the exiting, or the base condition is reached. When the condition is true, the previously generated values will be multiplied by each other, and the final factorial value is returned. 2. We declare and initialize an integer variable with value"6" and then print its factorial value by calling our factorial function. Explanation of Example 1 8 Example2: Write a program in C to print first 50 natural numbers using recursion. #include int numPrint(int); int main() { int n = 1; Example 2 printf("\n\n Recursion : print first 50 natural numbers :\n"); printf("-------------------------------------------------\n"); Recursive printf(" The natural numbers are :"); Function numPrint(n); printf("\n\n"); return 0; } int numPrint(int n) { if(n