0% found this document useful (0 votes)
1 views29 pages

C Programming

Chapter 1 introduces programming and problem-solving concepts, emphasizing the importance of structured programming and various approaches to problem-solving, including top-down and bottom-up methods. It discusses the characteristics of algorithms and the use of flowcharts and pseudocode for representing algorithms. The chapter also highlights the significance of problem-solving skills in personal and professional contexts.

Uploaded by

sarfrazahmad1809
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
1 views29 pages

C Programming

Chapter 1 introduces programming and problem-solving concepts, emphasizing the importance of structured programming and various approaches to problem-solving, including top-down and bottom-up methods. It discusses the characteristics of algorithms and the use of flowcharts and pseudocode for representing algorithms. The chapter also highlights the significance of problem-solving skills in personal and professional contexts.

Uploaded by

sarfrazahmad1809
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Chapter 1 Introduction to Programming & Problem Solving Learning Outcomes ‘After reading this chapter, students will be able to explain the concept of programming describe the concept of problem-solving and its need explain the concept of process and its types ~ adhoc and defined describe different approaches to problem-solving - top-down and bottom-up explain the concept of structured programming explain various control structures adhering to the requirement of structured programming explain the notion of an algorithm explain the desirable characteristics of a good algorithms represent an algorithm using a flowchart or a pseudocode solve variety of numerical and logical problems 2 Problem Solving and Programming in C 1.1 INTRODUCTION TO PROGRAMMING Programming is a way to instruct the computer to perform various tasks, Instruct the computer, basically means that you need to provide the computer with a set of instructions that are written in a language that the computer can understand, Perform various tasks, basically means finding the solution to a problem (task). The tasks could be small & simple that require few instructions to obtain their solution or large & complex one that may involve a large number of instructions Hence, in brief, Programming is a way to tell computers to do a specific task. The real problem with the current teaching & learning of programming (using any of C/C++/Java/Python/Kotlin) is that ultimately it reduces to teaching & learning of programming language only. Programming is not just about learning the syntax of the language, it is more about accomplishing the task ~ Problem Solving. 1.1.1 Problem Solving Problem-solving is a skill that anybody can learn with practice. Let us pause for while, and ask ourselves a simple question - what is a problem? The obvious answer is the absence of a solution. The moment you get a solution, the problem is no more a problem for you. Therefore, I wish that our education system must produce individuals, who can seek solutions to the problems they are facing or may face in future, the solution seekers We will learn about problem-solving, in more detail, in the next section. 1.1.2 Process A process is a series of steps or activities that interact to produce a solution. Whatever we do in our day-to-day life, we are always following certain series to steps to accomplish a task. Tam leaving this as a task for you ~ enumerate most of the daily activities you do, and what are the steps you follow to accomplish them. Chapter 1: Introduction to Programming & Problem Solving 3 [Link] Adhoe Process ‘A process where activities are not well-defined, and the solution is sought in a hhit-and-trial manner. Characteristics of an adhoc process: may or may not produce solution ‘othe outcome may not be traceable ‘© the solution may not be repeatable [Link] Defined Process A process that is well-defined and documented, ie., every step is clear and had been written in a form that one can understand easily. Characteristics of a defined process: ‘© solution is sought by following the steps prescribed in the document © willalways produce the solution ‘9 the outcome is always traceable ‘© the solution is always repeatable [Link] Tools to Document a Process Any one of the following tools can be used to document a defined process: © Algorithm © Flowchart © Pseudocode o Decision table © Decision tree In this textbook, we will discuss about algorithm, flowchart, and pseudocode. The remaining, tools ~ decision table and decision tree you will learn in the subjects where they possible used. 1.2 INTRODUCTION TO PROBLEM-SOLVING The ability to solve problems is a most basic life skill and is essential to our day-to-day lives, at home, at school, and at the workplace. 4 Problem Solving and Programming in C We solve problems every day without really thinking about how we solve them. For example, itis raining and you need to go to the market. What do you do? ‘There are a variety of possible solutions: © You can take your umbrella and walk down to the market. o Ifyou don't want to get wet, you can drive, or take the bus. © You might decide to call a friend for a ride, or you might decide to go to the market another day. The important point to note down here is that there is no right way to solve this problem and different people may solve it differently. Problem-solving is the process of identifying a problem, developing possible solution alternatives, and taking the appropriate course of action. Why is problem-solving important? Good problem-solving skills empower you not only in your personal life, but are very critical in your professional life. In the currently fast-changing global economy, employers often identify everyday problem solving as crucial to the success of their organizations. Chapter 1: Introduction to Programming & Problem Solving 5 For employees, problem solving can be used to develop practical and creative solutions and to show independence and initiative to employers. 1.3 APPROACHES TO PROBLEM SOLVING ‘There are two approaches to problem solving: © Top-down approach © Boltom-up approach 1.3.1 Top-Down Approach The basic idea of the top-down approach is to divide a complex problem into smaller sub-problems, this process is also called decomposition. The sub-problems are further divided into sub-problems and this process is continued until each sub-problem is atomic (can’t be divided further) and can be solved independently of other sub- problems. The top-down way of solving a program is the step-by-step process of breaking down the problem into chunks for organizing and solving the sole problem, Figure 1: Top-down process Structured programming languages, like the C programming language, use the top- down approach to solving a problem in which the flow of control is in the downward direction. 6 Problem Solving and Programming in C 1.3.2 Bottom-Up Approach ‘As the name suggests, this method of solving a problem works exactly opposite to the top-down approach. In this approach, we start working from the most basic level of problem solving and moving up in conjugation of several parts of the solution to achieve the required results. The most fundamental units, modules, and sub-modules are designed and solved individually, and these units are then integrated together to get a more concrete base for problem-solving, This bottom-up approach works in different phases or layers. Each module designed is tested at a fundamental level which means unit testing is done before the integration of the individual modules to get the solution. Sub Module 2.1 Figure 1.2; Bottom-up process The object oriented programming languages, like the C++ or Java programming language, uses the bottom-up approach to solving a problem in which the flow of control is in the upward direction. 1.3.3 Top-down v/s Bottom-up Approach Table 1.1 summarizes the key differences between top-down approach and bottom-up. approach, Chapter 1: Introduction to Programming & Problem Solving 7 Table 1.1: Top-down V/S Bottom-up Approach Top-down Approach Bottom-up Aj Divides a problem into smaller units and then solves it. Starts by solving small modules and adding them up together. This approach may contain redundant information, Redundancy can easily be eliminated. ‘A well-established communication is not ‘Communication among steps is required. mandatory. ‘The individual modules are thoroughly | Works on the concept of data-hiding analyzed. and encapsulation. Structured programming languages such as C uses a top-down approach. ‘OOP languages like C++ and Java ete uses a bottom-up mechanism. Relation among modules is not always required. ‘The modules must be related for better communication and workflow. Primarily used in code implementation, test case generation, debugging, and module documentation. Finds use primarily in testing. @ The top-down approach is the conventional approach in which the decomposition of the higher-level system into a lower-level sy place respectively while the bottom-up approach starts by designing lower fem takes abstraction modules and then integrating them into a higher-level system, 1.4 STRUCTURED PROGRAMMING Structured programming is a technique devised to improve the reliability and clarity of programs. In structured programming, control of program flow is restricted to the following three structures: © sequence © selection © iteration or toa structure derivable from a combination of these basic three structures, Each of these structures is described overleag, 8 Problem Solving and Programming in C 1.4. Sequence Structure In sequence structure, instructions are followed or executed one after another in sequence in which they appear. The flow of logic is from top to bottom, + instruction instruction-1 i instruction-2 instruction-2 , ‘ + instruction-3 instruction-3 Figure 1.3: Pseudocode and flowchart for sequence structure 1.4.2 Selection Structure Selection structure is used for making a decision. It is used for selecting a proper path out of the alternative paths in the program logic. Selection structure may take the form as either If... Endif or If... Else... Endif or If ElseIf... Else... Endif structure, The If... Endif structure says that if the expression is true, then execute statement else (if the expression is false) skip over the statement, ei true (expression ) then statement ° Endif false statement <__] Vv 'seudocode and flowchart for If... Endifselection structure Chapter 1: Introduction to Programming & Problem Solving 9 The If... Flse. . . Endif structure says that if the expression is true then execute statement-1, else (if the expression is faise) execute statement-2, Depending on the outcome of the expression being tested, if there are multiple alternatives (execution paths), then If... Else If... Else... Endif structure is a very handy structure false true If ( expression ) then statement-1 Bise statement-2 Enda Figure 15: Pseudocode and flowchart for If... Else... Enuif selection structure Tf ( expression-1 ) then statement-1 Else If ( expression-2 } thea statement~2 Else Tf ( expression-3 } then statement-3 Else If ( expression-n ) then statement=n Else statenent-s Bndif| Figure 1.6: Syntax of If... ElseIf... Else... Endif structure ‘The expressions are evaluated in order, and if any expression is true then the statement block associated with itis executed, and this terminates the whole chain, ‘The last else part handles none of the above where none of the specified expressions are satisfied 10 Problem Solving and Programming in C wre 1.7: Logie flow of If... Else If... Else... Endif structure 1.4.3 Iterative Structure ‘The iterative structure is used to produce loops when one or more instructions are to be executed either a given number of times or till a certain condition is met. The following two iterative structures are used: © While... Enduohite 0 For... Endfor while ( expression } tre statement Endwhile Figure 18: Pseudocode and flowchart for While... Endtohile iterative structure Chapter 1: Introduction to Programming & Problem Solving 11 ‘The While... . Endzohile iterative structure will continue executing until the expression is true. However, if statement or a certain group of statements are to be executed for a known number of times, the For .. . Endfr iterative structure isa better choice, For i = rte g in steps of & statement Endfo Figure 1.9: Syntax for For... Enufor iterative structure It uses an index variable i to control the loop. Here r is called the initial value, s is called the final value, and t is called the step size, which may be positive (increment) or negative (decrement) g (a) When step size tis positive (8) When step size tis negative Figure 1.10: Working of for statement for positive and negative step size 2 Problem Solving and Programming in C 1.5 ALGORITHMS An algorithm is a finite sequence of steps defining the solution of a particular problem, Characteristics of a good algorithm: There are five important characteristics of an algorithm that should be considered while designing an algorithm for a problem. Input: An algorithm must have zero or more but a finite number of inputs, which are externally supplied. An example of zero input algorithms can be to find the sum of the first 100 natural numbers. Here, the user doesn’t need to supply any external input since it is already specified to find the sum of the first 100 natural numbers. However, if the above problem is re-stated as finding the sum of first 1 natural numbers, the user is required to provide single input denoting the value form (Output: An algorithm must have at least one desirable outcome, ie, output, Definiteness (No ambiguity): Fach step must be clear and unambiguous, ic, having one and only one meaning, Finiteness: If we trace the steps of an algorithm, then for all cases, the algorithm must terminate after a finite number of steps. Effectiveness: Each step must be sufficiently basic that it can in principle be carried out by a person using only paper and pencil. In addition, not only should each step be definite, but it must also be feasible. ‘An algorithm can be represented using a flowchart or pseudocode. 1.5.1 Flowchart A flowchart is a pictorial representation of an algorithm. It uses different shapes to denote different types of instructions. The actual instructions are written within the shapes using clear and concise statements. These shapes are connected by directed lines to indicate the sequence in which instructions are to be executed. Table 1.2 shows various symbols used in flowcharts along with their name and brief description. Chapter 1: Introduction to Programming & Problem Solving 13 ‘Table 1.2: Various flowchart symbols and their brief description ‘Symbol Name Purpose oval Terminal - to mark the beginning and end of the program logic flow, Input/Output - to denote input to the program or © — La Parallelogram | output from the program. 7 Processing - to denote arithmetic operations and Rectangle | movement of data, Diamond | Détison - to denote a point where decision has to be made to branch to one of the alternatives, Gmatlaincie | Comnector ~ To provide a Togical Tink Between segments of a flowchart Flow Lines - To indicate the sequence in which Directed lines | ; structions are to be executed Print “Roots are ‘maginary Padac <0 ‘Compare \_ 64a >0 Pasac with 0 Print "Roots are Print “Roots are real & equal real & distin! Figure 1.11: Flowchart to find the nature of roots of a quadratic equation 14 Problem Solving and Programming in C 1.5.2 Pseudocode The word “pseudo” means imitation or false and the word “code” refers to the instruction written in a programming language. Pseudocode, therefore, is an imitation of actual computer instruction. Pseudo instructions are phrases written in English like statements. Instead of using symbols to describe the logic of the program, as in flowcharts, pseudocode uses a structure that resembles computer instructions. Because, it emphasizes the design of the program, pseudocode is also called Program Design Language (PDL), Pseudocode is made up of the following basic logic structures that have proved to be sufficient for writing any computer program: 1. Sequence 2 Selection (If... Endif, If... Else... Endif If... Else If... Ena) 3. Iteration (While... Endechile, Do... While) We have already discussed about these logic structures under the heading of structured programming. Pseudocode Description Comments Each instruction may be followed by a comment. The comments begin with a double slash, and the explain the purpose of the instruction, such as Read: —_// Enter the value of variable n Appropriate use of comments enhances the readability of the pseudocode, which in tum helps in maintaining the pseudocode Variable Names For variable names, we will use italicized lowercase letters such as max, loc, etc, whereas for defined constants, if any, we will use uppercase letters. Assignment Statement ‘The assignment statement will use the notation as Set max OR max = a to assign the value of a to max. The right hand side of the assignment statement can have a value, a variable or an expression. Chapter 1: Introduction to Programming & Problem Solving 15 However, if several assignment statements appear in the same line, such as Setk=1,loc=1,mav=a OR k= 1,loc=1, max = a then they are executed from left to right. Input/Output Data may be input and assigned to variables by means of a read statement with the following format Read: Variable list where the Variable list consists of one or more variables separated by comma. Similarly, the data held by the variables and the messages, if any, enclosed in double quotes can be output by means of a print statement with the following format Pri tesage and /or Variable list where the message and the variables in the Variable list are separated by comma. Execution of Instructions ‘The instructions are usually executed one after the other as they appear in the pseudocode. However, there may be instances when some instructions are skipped or some instructions may be repeated as a result of certain expressions Completion of the Algorithm ‘A pseudocode is completed with execution of the last instruction. However, it can be terminated at any intermediate state using the exit instruction. Pseudocode to display the nature of roots of a quadratic equation of the type a+bx+tc=0 provided a +0 Pseudocode 1.1 Begin Print: “Roots arc ral and equal” ElseIf (dise>0) then “Roots are real end distinct” 16 Problem Solving and Programming in C ILLUSTRATIVE EXAMPLES Example 1.1: Draw a flowchart and write a pseudocode to swap (interchange) two variables say a and b. Solution: Think of the scenario - we have water in one glass and juice in another glass. We want to have water in a glass in which we have juice, and juice in a glass in which we have water. How can this task be accomplished? Ina similar way, we have to use a third variable values of two variables. 1, to facilitate the swapping of Begin Set1=a "Read: Ye Set fo variables Figure 1.12: Flowchart and pseudocode to swap Example 1.2: Draw a flowchart and write a pscudocode to test whether a given natural number’n’ is even or odd. Solution: You all may know that any natural number is even if itis exactly divisible by 2, ie, division by 2 gives 0 as remainder. The operation of obtaining remainder is called modulo (mod in short) operation. Pseudocode 1.3, Be Read: n If (mod 2 = 0) the Print: n, “is Even Else Print: n, “is Oda” Endif End. Chapter 1: Introduction to Programming & Problem Solving 17 Print: n, is Odd” Figure 1.13: Flowchart to test whether a given number is Even or Odd. Example 1.3: Draw a flowchart and write pseudocode to find the largest of three numbers; say 4, B Solution: We first compare a with b. If «is greater than b then we compare a with c. If a is greater than c, then a is taken as the largest number otherwise we take c as the largest number. However, if a is not greater than b, we compare b with c. If b is greater than c then bis taken as the largest number otherwise we take cas the largest number. =) Las Print © Figure 1.14: Flowchart and pseudocode to find largest of three numbers 18 Problem Solving and Programming in C Pseudocode 1.4 Begin Read: a, 5,6 If (a >b) If (a >c) then Print: a Else Print: © Endif| Ele If (b>c) then Print: b Else Pr Endif Endif End. Example 1.4: Based on the percentage of marks in a subject, letter grade is assigned toa student as per the following examination policy: Percentage of Marks Gade percentage 2 90 At 90> percentage 280 A 80> percentage 270 B 70> percentage > 60) Cc 60> percentage > 50 D percentage <50 F Write pseudocode to assign a letter grade to a student whose percentage of marks ina subject is given. Pseudocode 1.5 Begin Read: percentage If (percentage >= 90 ) Print: “Grade = A+" Else If (percentage >= 80) Print: “Grade~ A" Else If (percentage >= 70) Print: “Grade = B Else If (percentage >= 60) Print: “Grade = C" Else If (percentage >= 50) Chapter 1: Introduction to Programming & Problem Solving 19 Example 1.5: Commission on sales by a salesman is calculated as per following policy: “Amount of Sale Gm Ra) Commission Rate] 0 5000 Nil | Boor = 100007 5 i excess of 5000 | 10001 — 15000 7 excess of 10000 } > 15000 10 % excess of 15000 Draw a flowchart and write a pseudocode that accepts sales made by a salesman and displays the commission due. Solution: Me Yes Set commission ~ (sales — Issales < 15,0002 Set commission = 250" 0.075* (sales - 10000 ) Set comission = 0.1* (sales ~ 15000 ) Figure 1.15: Flowchart to compute the commission 20. Problem Solving and Programming in C Pseudocode 1.6 Begin Read: sales If (sales <= 5000 ) ‘Set commission = 0 Else If (sales <= 10000 ) ‘Set commission = (sales ~ 5000) * 0.05; Else If (sales <= 15000) ‘Set commission = 250 + (sales ~ 10000) * 0.075; Ehe ‘Set commission = 1000 + ( sales ~ 15000 )* 0.1; Endif Print: “Computed commission End. Example 1.6: Draw a flowchart and write pseudocode to find the sum of digits of a number 1. Solution: pve Setd=n mod 10 Figure 1.16: Flowchart to find the sum of digits of a number Pseudocode 1.7 Begin Read: » Set ‘While (> 0) do ‘Set d= n mod 10 Chapter 1: Introduction to Programming & Problem Solving 21 Example 1.7: Draw a flowchart and write pseudocode to check whether the given number m is palindrome or not. Solution: 'A ine ealledpaindrme i eade same from both the ends. For example, the fun Sern ¥ ses=0 1991 is a palindrome, whereas the Sets-sx 10d + Sets=1/10 Figure 1.17: Flowchart to check whether the given number n is palindrome or not Pseudocode 1.8 Begin Read: Setr=n, s=0 ‘While (1>0) do ‘Set Set Set Endwhi 22 Problem Solving and Programming in C If (s=7) then Print: “Palindrome” Else Print: “Nota Palindrome” Endif End. Example 1.8: Draw a flowchart and write a pseudocode to check whether the given number 11 is an Armstrong number or not, C sun) ‘A number is called Armstrong if sum of cube of its digits equals the number itself. For example, 153 is However, number 135 is not an Armstrong number, Sern since Solution: 5? =14.27 4125 =153 7135 Print Print Sets tea Amstrong” Not Armstrong” + J Sette 10 Figure 1.18: Flowchart to check whether the given number is an Armstrong number or not Pseudocode 1.9 Begin Read: While (7>0) do mod 10 tdxded 110 If (s=n) then Print: “Armstrong” Chapter 1: Introduction to Programming & Problem Solving 23 Else Print: “Not Armstrong” Endit End. Example 1.9: Draw a flowchart to find whether the given natural number 1 is a prime number or not. Solution: A natural number is said to be prime if tis divisible by 1 and itself only, ie., it cannot be factorized. In addition, to this definition, an even number except 2 is not a prime number. Therefore, our test criteria becomes 1. If mis greater than 2 and is even then n is not a prime number. 2. If test at step 1 fails, then we try to divide number n by factors k = 3, 5,7, ... Vm. ‘Therefore, if mis divisible by any value of k, number n is not a prime number. 3. If test at step 2 also fails, then mis a prime number. Isn>2and divisible by 22 ‘Assign value of vito m q ‘Assign value 3 10 & Figure 1.19: Flowchart to check whether number m is prime or not 24 Problem Solving and Programming in C The following is the pseudocode to find whether the given positive number 1 is a prime number or not. Pseudocode 1.10 Begin Read: n If (> 2 and n mod 2 == 0) then Print: n,“ is not a prime number" Exit Ele setm= Vn For k=3t0mby2do It(nmod k— 0) then Print: n, "is nota prime number” Exit Example 1.10: To find the highest common factor (HCF), also known as the greatest common divisor (GCD), of two natural numbers m and n. Solution: San <— wuotiont divisor —> 73 Ze 79 <— remainder dividend 0 aT =0 3 20 0 Figure 1.20: Illustration of computational procedure for HCF/GCD Figure 1.20 demonstrates the long/continued division method to find the HCF/GCD of two natural numbers. You must have observed that in successive divisions, the divisor of the previous division becomes dividend, remainder of becomes divisor, and division is again carried out. This process is continued till the reminder becomes zero, and the current divisor is taken as HCF/GCD of the given natural numbers, Chapter 1: Introduction to Programming & Problem Solving 25 This process can be implemented by using the following steps 1. Perform division. 2. If remainder is zero, then stop and take the divisor as HCF/GCD. 3. Replace dividend by divisor. 4. Replace divisor by remainder. 5. Repeat from step 1 Beendosode LIL Begin Srimy While (70) Zp 7 sar Setn=r | Set =m mod n =e]! t Stop Replace m by n and n by r Ly igure 1.21: Flowchart and pseudocode to compute HCF of two numbers Example 1.11: Draw a flowchart and write a pseudocode to print first terms of the Fibonacci sequence For example, if input value for 1 is 8, the output should be 01123 5 8 13 Solution: Observe that, leaving first two terms, each term is obtained as the sum of the immediately preceding two terms, If we use variable prev for previous term, curr for current term, next for next term, and setting prev and curr to values 0 and 1, respectively, ie, first two terms of the sequence, then the entire sequence can be generated by using the recurrence relation next = preo + curr replace prev by curr replace curr by next 26 Problem Solving and Programming in C Pseudocode 1.12 Lima _ Set prev= 0, cwr=1 Setprev=Ojcwr= 1 Set cow int: prev, curr * While (count Ant main() ‘ int ny ty sum, dy print! ("Enter any natural number scanf ("$d", én); while (t > 0) { d=t 810 sun = sum * 10 + dy t=t/ 10; d Af ( sum ==) printf ("\ntd is a palindrome number. \n", n); else printf ("\nid is not a palindrome number.\n", n); return 0; ) “First Program Rum Enter any natural number : 1221 3221 is a palindrome nunber. Enter any natural number : 1205 1205 is not a palindrome nunber. We will be learning about C language in subsequent chapters. peeee What do you understand by the term programming? Elaborate. What is problem-solving? What is the need for problems-solving? What is a process? Differentiate between adhoc process and defined process Name the various approaches for problem solving. Describe the top-down approach of problem solving. 28 10. u Problem Solving and Programming in C Describe the bottom-down approach of problem solving. Differentiate between top-down approach and bottom-up approach to problem solving, What do you mean by structured programming? Describe the various control structures that meet the requirement of structured. programming. What is an algorithm? Describe the essential characteristics of an algorithm. Given a choice to represent the solution of a problem by flowchart or pseudocode, which you will prefer and why? Elaborate. NUMERICAL AND LOGICAL PROBLEMS Solve following numerical and logical problems and express their solution using flowchart/ pseudocode: 1 2 3 To find largest ofthe five numbers a, b,c, and e. To find the day of the week on a given date. To test whether a given year is a leap year or not. [Hint: A given year will be a leap year if itis divisible by 4 but not by 100. Ifa year is divisible by 4 and by 100, itis not a leap year unless itis also divisible by 400.] To test whether the given date in format dd/mm/ yyyy is valid or not. To test whether a given number is a perfect number or not. (Hint: A perfect number is a number in which the sum of its proper divisors is equal to the number itself. Proper divisors of a number are all divisors of a number excluding itself] To test whether a given number is strong number or not. [Hint: A strong number is a number whose sum of the factorial of its each digit equals to the number itself] Suppose an amount p is deposited in a commercial bank, which pays compound interest at the rate of r% annually, for n years, Write @ pseudocode that prints the amount in account after each year To find LCM and HCF of two natural number m and 7 ‘To find factorial of a natural number 2. To print first n pairs of twin prime numbers. Note that two consecutive prime numbers are said to twin prime numbers if they differ by 2 The monthly telephone bill is to be computed as follows; Minimum Rs. 200 for upto 100 calls plus Rs. 0.60 per call for next 50 calls plus Rs. 0.50 per call for next 50 calls plus Rs. 0.40 per call for any call beyond 200 calls. The input contains name of the customer and number of calls made and the desired output is the name and telephone bill to be paid by the customer. R 14. 15. 16. 7. 18. 19. 20. 21 2, Chapter 1: Introduction to Programming & Problem Solving 29 State pollution control board has the following classification policy: Pollution Index | Classification < 30 Pleasant 30-60 Unpleasant > 60 “Hazardous ‘To prints the appropriate classification for given pollution index. ‘A department store places an order with a company for n pieces of miners, m pieces of toasters, and p number of fans. The cost of items are as follows Ttem Description _| Price per Unit (in Rupees) Miners 1,500) Toaster 200 Fan 450 The discount allowed for various items are 5% for miners, 15% for fan, and 10% for toaster. The company charge 10% as sales tax on all items on net value after deducting the discount. To compute the amount to be paid by the store for given value of m, n, and p. To check whether a triangle can be formed or not from given three line segments whose measure is given as a, band c. To check whether a triangle can be formed or not from given three angles whose measure is given as a, b, and c. ‘To find the type of the angle when a measure of one angle is given in degrees and in anti-clockwise direction. Given three points A(t, 92), B(t2 ya) and C(xs, ys), to determine whether they are collinear, i¢,, lie on the same line. Given points (x1, ys) & (22, y2) on Tine AB, and points (xs, ys) & (x4, ys) on line CD, write a the steps to determine whether lines AB & CD intersect each other. To find your age when your date-of-birth and today’s date is given, both in the format dd/mm/yyyy. To find convert a time in 12 hours system to 24 hours system. To find convert a time in 24 hours system to 12 hours system, To find difference in time when the start time and ending time is given, both in the format hlimimess

You might also like