You don’t have to be great to start, but you have to start to be great.
--Your friends at LectureNotes

Note for Problem Solving And Programming In C - PSPC By auxilia nancy

  • Problem Solving And Programming In C - PSPC
  • Note
  • 8 Offline Downloads
  • Uploaded 9 months ago
Auxilia Nancy
Auxilia Nancy
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

ALGORITHMIC PROBLEM SOLVING 1. What is an algorithm? Algorithm is an ordered sequence of finite, well defined, unambiguous instructions for completing a task. It 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. 2. Write an algorithm to find minimum of 3 numbers in a list. ALGORITHM : Find Minimum of 3 numbers in a list Step 1: Start Step 2: Read the three numbers A, B, C Step 3: Compare A and B. If A is minimum, go to step 4 else go to step 5. Step 4: Compare A and C. If A is minimum, output “A is minimum” else output “C is minimum”. Go to step 6. Step 5: Compare B and C. If B is minimum, output “B is minimum” else output “C is minimum”. Step 6: Stop 3. List the building blocks of an algorithm. The building blocks of an algorithm are Statements Sequence Selection or Conditional Repetition or Control flow Functions 4. Define statement. List its types. Statements are instructions in Python designed as components for algorithmic problem solving, rather than as one-to-one translations of the underlying machine language instruction set of the computer. There are three types of high-level programming language statements Input/output statements make up one type of statement. An input statement collects a specific value from the user for a variable within the program. An output statement writes a message or the value of a program variable to the user’s screen.

Text from page-2

5. Write the pseudo code to calculate the sum and product of two numbers and display it. INITIALIZE variables sum, product, number1, number2 of type real PRINT “Input two numbers” READ number1, number2 COMPUTE sum = number1 + number2 PRINT “The sum is “, sum COMPUTE product = number1 * number2 PRINT “The Product is “, product END program 6. How does flow of control work? Control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. A control flow statement is a statement in which execution results in a choice being made as to which of two or more paths to follow. 7. What is a function? Functions are "self-contained" modules of code that accomplish a specific task. Functions usually "take in" data, process it, and "return" a result. Once a function is written, it can be used over and over and over again. Functions can be "called" from the inside of other functions. 8. Give the rules for writing Pseudo codes. Write one statement per line. Capitalize initial keywords. Indent to show hierarchy. End multiline structure. Keep statements to be language independent.

Text from page-3

9. Give the difference between algorithm, flowchart and pseudo code. S. No Algorithm Flow Chart Pseudo Code 1 Sequence of instruction to solve the Particular Problem Pictorial Representation of algorithm Sequence of instruction to solve the Particular Problem 2 It’s pure English Language, it It has symbol to Represent has no rules to write the instruction It’s a English language But it has, some set of rules 3 It’s not a tool for document purpose Flow chart are tools document and represent algorithm Pseudo code are toosl document represent and Algorithm 4 Sequence of instruction to solve the Particular Problem Pictorial representation of algorithm using standard symbols. Rules of structured design & programming. 10. Define a flowchart. A flowchart is a diagrammatic representation of the logic for solving a task. A flowchart is 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. 11. Give an example of iteration. a=0 for i from 1 to 3 // loop three times { a=a+I // add the current value of i to a } print a // the number 6 is printed (0 + 1; 1 + 2; 3 + 3) 12. Write down the rules for preparing a flowchart. While drawing a flowchart, some rules need to be followed— (1) A flowchart should have a start and end, (2) The direction of flow in a flowchart must be from top to bottom and left to right, and

Text from page-4

(3) The relevant symbols must be used while drawing a flowchart. 13. List the categories of Programming languages. Programming languages are divided into the following categories: Interpreted, Functional, Compiled, Procedural, Scripting, Markup, Logic-Based, Concurrent and Object-Oriented Programming Languages 14. Mention the characteristics of an algorithm. Algorithm should be precise and unambiguous. Instruction in an algorithm should not be repeated infinitely. Ensure that the algorithm will ultimately terminate. Algorithm should be written in sequence. Algorithm should be written in normal English. Desired result should be obtained only after the algorithm terminates. 15. Compare machine language, assembly language and high-level language. • • • Machine language is a collection of binary digits or bits that the compute read s and interprets. This language is not easily understandable by the human. An assembly language directly controls the physical hardware. A program written in assembly language consists of a series of instructions mnemonics that correspond to a stream of executable instructions, when translated by an assembler can be loaded into memory and executed. The programs written in this language are not portable and the debugging process is also not very easy. A high level language is much more abstract, that must be translated or compiled in to machine language. It is easily understandable and the programs are portable. Debugging the code is easy and the program written is not machine dependent. 16. List out the simple steps to develop an algorithm. Algorithm development process consists of five major steps. Step 1: Obtain a description of the problem. Step 2: Analyze the problem. Step 3: Develop a high-level algorithm. Step 4: Refine the algorithm by adding more detail. Step 5: Review the algorithm.

Lecture Notes