In this lesson, we are going to learn Problem Solving Through Programming in C. This is the first lesson while we start learning the C language.

So let’s start learning the C language.

Introduction to Problem Solving Through Programming in C

Regardless of the area of the study, computer science is all about solving problems with computers. The problem that we want to solve can come from any real-world problem or perhaps even from the abstract world. We need to have a standard systematic approach to problem solving through programming in c.

computer programmers are problem solvers. In order to solve a problem on a computer, we must know how to represent the information describing the problem and determine the steps to transform the information from one representation into another.

In this chapter, we will learn problem-solving and steps in problem-solving, basic tools for designing solution as an algorithm, flowchart, pseudo code etc.

Problem Solving Through Programming in C

A computer is a very powerful and versatile machine capable of performing a multitude of different tasks, yet it has no intelligence or thinking power.

The Computer performs many tasks exactly in the same manner as it is told to do. This places responsibility on the user to instruct the computer in a correct and precise manner so that the machine is able to perform the required job in a proper way. A wrong or ambiguous instruction may sometimes prove dangerous.

The computer cannot solve the problem on its own, one has to provide step by step solutions of the problem to the computer. In fact, the task of problem-solving is not that of the computer.

It is the programmer who has to write down the solution to the problem in terms of simple operations which the computer can understand and execute.

Problem-solving is a sequential process of analyzing information related to a given situation and generating appropriate response options.

In order to solve a problem with the computer, one has to pass through certain stages or steps. They are as follows:

Steps to Solve a Problem With the Computer

problem solving through programming in c

Step 1: Understanding the Problem:

Here we try to understand the problem to be solved in totally. Before with the next stage or step, we should be absolutely sure about the objectives of the given problem.

Step 2: Analyzing the Problem:

After understanding thoroughly the problem to be solved, we look at different ways of solving the problem and evaluate each of these methods.

The idea here is to search for an appropriate solution to the problem under consideration. The end result of this stage is a broad overview of the sequence of operations that are to be carried out to solve the given problem.

Step 3: Developing the solution:

Here, the overview of the sequence of operations that was the result of the analysis stage is expanded to form a detailed step by step solution to the problem under consideration.

Step 4: Coding and Implementation:

The last stage of problem-solving is the conversion of the detailed sequence of operations into a language that the computer can understand. Here, each step is converted to its equivalent instruction or instructions in the computer language that has been chosen for the implantation.

The vehicle for the computer solution to a problem is a set of explicit and unambiguous instructions expressed in a programming language. This set of instruction is called a program with problem solving through programming in C.

A program may also be thought of as an algorithm expressed in a programming language. an algorithm, therefore, corresponds to a solution to a problem that is independent of any programming language.

To obtain the computer solution to a problem once we have the program we usually have to supply the program with input or data. The program then takes this input and manipulates it according to its instructions. Eventually produces an output which represents the computer solution to the problem.

The problem solving is a skill and there are no universal approaches one can take to solving problems. Basically one must explore possible avenues to a solution one by one until she/he comes across the right path to a solution.

In general, as one gains experience in solving problems, one develops one’s own techniques and strategies, though they are often intangible. Problem-solving skills are recognized as an integral component of computer programming.

Note: Practice C Programs for problem solving through programming in C.

Problem Solving Steps

Problem-solving is a creative process which defines systematization and mechanization. There are a number of steps that can be taken to raise the level of one’s performance in problem-solving.

A problem-solving technique follows certain steps in finding the solution to a problem. Let us look into the steps one by one:

1. Problem Definition Phase:

The success in solving any problem is possible only after the problem has been fully understood. That is, we cannot hope to solve a problem, which we do not understand. So, the problem understanding is the first step towards the solution of the problem.

In the problem definition phase, we must emphasize what must be done rather than how is it to be done. That is, we try to extract the precisely defined set of tasks from the problem statement.

Inexperienced problem solvers too often gallop ahead with the task of the problem – solving only to find that they are either solving the wrong problem or solving the wrong problem or solving just one particular problem.

2. Getting Started on a Problem:

There are many ways of solving a problem and there may be several solutions. So, it is difficult to recognize immediately which path could be more productive. Problem solving through programming in C.

Sometimes you do not have any idea where to begin solving a problem, even if the problem has been defined. Such block sometimes occurs because you are overly concerned with the details of the implementation even before you have completely understood or worked out a solution.

The best advice is not to get concerned with the details. Those can come later when the intricacies of the problem have been understood.

3. Use of Specific Examples:

To get started on a problem, we can make use of heuristics i.e the rule of thumb. This approach will allow us to start on the problem by picking a specific problem we wish to solve and try to work out the mechanism that will allow solving this particular problem.

It is usually much easier to work out the details of a solution to a specific problem because the relationship between the mechanism and the problem is more clearly defined.

This approach of focusing on a particular problem can give us the foothold we need for making a start on the solution to the general problem.

4. Similarities Among Problems:

One way to make a start is by considering a specific example. Another approach is to bring the experience to bear on the current problems. So, it is important to see if there are any similarities between the current problem and the past problems which we have solved.

The more experience one has the more tools and techniques one can bring to bear in tackling the given problem. But sometimes, it blocks us from discovering a desirable or better solution to the problem.

A skill that is important to try to develop in problem-solving is the ability to view a problem from a variety of angles.

One must be able to metaphorically turn a problem upside down, inside out, sideways, backwards, forwards and so on. Once one has developed this skill it should be possible to get started on any problem.

5. Working Backwards from the Solution:

In some cases, we can assume that we already have the solution to the problem and then try to work backwards to the starting point. Even a guess at the solution to the problem may be enough to give us a foothold to start on the problem.

We can systematize the investigations and avoid duplicate efforts by writing down the various steps taken and explorations made.

Another practice that helps to develop the problem-solving skills, once we have solved a problem, to consciously reflect back on the way we went about discovering the solution.

General Problem Solving Strategies:

problem solving through programming in c

There are a number of general and powerful computational strategies that are repeatedly used in various guises in computer science.

Often it is possible to phrase a problem in terms of one of these strategies and achieve considerable gains in computational efficiency.

1. Divide and Conquer:

The most widely known and used strategy, where the basic idea is to break down the original problem into two or more sub-problems, which is presumably easier or more efficient to solve.

The Splitting can be carried on further so that eventually we have many sub-problems, so small that further splitting is no necessary to solve them. We shall see many examples of this strategy and discuss the gain in efficiency due to its application.

2. Binary Doubling:

This is the reverse of the divide and conquers strategy i.e build-up the solution for a larger problem from solutions and smaller sub-problems.

3. Dynamic Programming:

Another general strategy for problem-solving which is useful when we can build-up the solution as a sequence of the intermediate steps. Problem Solving through programming in C.

The travelling salesman problem falls into this category. The idea here is that a good or optimal solution to a problem can be built-up from good or optimal solutions of the sub-problems.

4. General Search, Back Tracking and Branch-and-Bound:

All of these are variants of the basic dynamic programming strategy but are equally important.