What is Problem Solving in Programming?
Computers are used to solve various problems in day-to-day life. Problem Solving is an
essential skill that helps to solve problems in programming. There are specific steps to
be carried out to solve problems in computer programming, and the success depends
on how correctly and precisely we define a problem. This involves designing, identifying
and implementing problems using certain steps to develop a computer.
Steps Involved in Problem Solving
Before being ready to solve a problem, there are some steps and procedures to be
followed to find the solution. Let's have a look at them in this problem solving in
programming article.
Basically, they are divided into four categories:
Analysing the problem
Developing the algorithm
Coding
Testing and debugging
Analysing the Problem
Every problem has a perfect solution; before we are ready to solve a problem, we must
look over the question and understand it. When we know the question, it is easy to find
the solution for it. If we are not ready with what we have to solve, then we end up with
the question and cannot find the answer as expected. By analysing it, we can figure out
the outputs and inputs to be carried out. Thus, when we analyse and are ready with the
list, it is easy and helps us find the solution easily.
Developing the Algorithm
It is required to decide a solution before writing a program. The procedure of
representing the solution in a natural language called an algorithm. We must design,
develop and decide the final approach after a number of trials and errors, before
actually writing the final code on an algorithm before we write the code. It captures and
refines all the aspects of the desired solution.
Coding
Once we finalise the algorithm, we must convert the decided algorithm into a code or
program using a dedicated programming language that is understandable by the
computer to find a desired solution. In this stage, a wide variety of programming
languages are used to convert the algorithm into code.
Testing and Debugging
The designed and developed program undergoes several rigorous tests based on
various real-time parameters and the program undergoes various levels of simulations.
It must meet the user's requirements, which have to respond with the required time. It
should generate all expected outputs to all the possible inputs. The program should also
undergo bug fixing and all possible exception handling. If it fails to show the possible
results, it should be checked for logical errors.
The problem solving tools include three unique categories: problem solving diagrams,
problem solving mind maps, and problem solving software solutions.
They include:
1. Fishbone diagrams
2. Flowcharts
3. Strategy maps
4. Mental maps
5. Idea maps
6. Concept maps
1
7. Layered process audit software
8. Charting software
9. MindManager
Programme
A computer program consists of code that is executed on a computer to perform particular tasks.
This code is written by programmers.
programming
Programming is the process of giving machines a set of instructions that describe how a program
should be carried out.
. It’s used to write software programs and applications, and to control and manipulate computer
systems. There are many different programming languages, each with its own syntax, structure,
and set of commands. Some of the most commonly used programming languages include Java,
Python, C++, JavaScript, and C#. The choice of programming language depends on the
specific requirements of a project, including the platform being used, the intended audience,
and the desired outcome. Programming languages continue to evolve and change over time,
with new languages being developed and older ones being updated to meet changing needs.
Some of the key features of programming languages include:
1. Syntax: The specific rules and structure used to write code in a programming language.
2. Data Types: The type of values that can be stored in a program, such as numbers, strings,
and booleans.
3. Variables: Named memory locations that can store values.
4. Operators: Symbols used to perform operations on values, such as addition, subtraction,
and comparison.
5. Control Structures: Statements used to control the flow of a program, such as if-else
statements, loops, and function calls.
6. Libraries and Frameworks: Collections of pre-written code that can be used to perform
common tasks and speed up development.
7. Paradigms: The programming style or philosophy used in the language, such as
procedural, object-oriented, or functional.
Examples of popular programming languages include Python, Java, C++, JavaScript, and
Ruby.
Types of programming language
1. Low-level programming language Low-level language is machine-dependent (0s and 1s)
programming language. The processor runs low- level programs directly without the
need of a compiler or interpreter, so the programs written in low-level language can be
run very fast. Low-level language is further divided into two parts –
i. Machine Language Machine language is a type of low-level programming language. It
is also called as machine code or object code. Machine language is easier to read because
it is normally displayed in binary or hexadecimal form (base 16) form. It does not require
a translator to convert the programs because computers directly understand the
machine language programs. The advantage of machine language is that it helps the
programmer to execute the programs faster than the high-level programming language.
ii. Assembly Language :-Assembly language (ASM) is also a type of low-level
programming language that is designed for specific processors. It represents the set of
instructions in a symbolic and human-understandable form. It uses an assembler to
convert the assembly language to machine language. The advantage of assembly
language is that it requires less memory and less execution time to execute a program.
2. Middle-level programming language Middle-level programming language lies between
the low-level programming language and high-level programming language. It is also
2
known as the intermediate programming language and pseudo-language. A middle-level
programming language's advantages are that it supports the features of high-level
programming, it is a user-friendly language, and closely related to machine language and
human language. Example: C, C++, language
3. High-level programming language High-level programming language (HLL) is
designed for developing user-friendly software programs and websites. This
programming language requires a compiler or interpreter to translate the program into
machine language (execute the program). The main advantage of a high-level language is
that it is easy to read, write, and maintain. High-level programming language includes
Python, Java, JavaScript, PHP, C#, C++, Objective C, Cobol, Perl, Pascal, LISP, FORTRAN,
and Swift programming language.
A high-level language is further divided into three parts –
i. Procedural Oriented programming language Procedural Oriented Programming
(POP) language is derived from structured programming and based upon the procedure
call concept. It divides a program into small procedures called routines or functions.
Example: C, FORTRAN, Basic, Pascal, etc.
ii. Object-Oriented Programming language Object-Oriented Programming (OOP)
language is based upon the objects. In this programming language, programs are divided
into small parts called objects. It is used to implement real-world entities like
inheritance, polymorphism, abstraction, etc in the program to makes the program
resusable, efficient, and easy-to-use. The main advantage of object-oriented
programming is that OOP is faster and easier to execute, maintain, modify, as well as
debug. [Link] Note: Object-Oriented Programming language follows a bottom-
up approach. Example: C++, Java, Python, C#, etc.
iii. Natural language Natural language is a part of human languages such as English,
Russian, German, and Japanese. It is used by machines to understand, manipulate, and
interpret human's language. It is used by developers to perform tasks such as
translation, automatic summarization, Named Entity Recognition (NER), relationship
extraction, and topic segmentation. The main advantage of natural language is that it
helps users to ask questions in any subject and directly respond within seconds.
Programs and Problem Solving
A program is a list of instructions or program statements composed in such a way as to enable a
computer to solve a problem. The problem to be solved is broken down into successively smaller
parts. These parts should form a well defined structure, the large complex problem at the top the
small easy to handle problems at the bottom. Hence the term top down programming.
To get a programming language to help you solve a problem, follow the steps below.
1. State the problem in English
2. Examine the problem and break down into several parts.
3. Examine the parts and refine into smaller parts.
4. Sketch a picture/structure plan
5. Write the main program with references to the subprograms.
6. Test the program.
3
Types of Error in C
Errors in C programming can disrupt the intended functionality of a program, causing issues
such as failed compilation, program crashes, or incorrect output. There are several common
types of errors:
Syntax Error
Run-Time Error
Logical Error
Semantic Error
Linker Error
1. Syntax Errors
These are also referred to as compile-time errors. These errors have occurred when the rule of
C writing techniques or syntaxes has been broken. These types of errors are typically flagged
by the compiler prior to compilation.
Example 1: In the below program we are getting an error because of a missing
semicolon at the end of the output statement (printf()) called syntax error.
2. Runtime Errors
This type of error occurs while the program is running. Because this is not a compilation error,
the compilation will be completed successfully. These errors occur due to segmentation fault
when a number is divided by division operator or modulo division operator.
3. Logical Errors
Even if the syntax and other factors are correct, we may not get the desired results due to
logical issues. These are referred to as logical errors. We sometimes put a semicolon after a
loop, which is syntactically correct but results in one blank loop. In that case, it will display the
desired output.
Linker Errors
When the program is successfully compiled and attempting to link the different object files
with the main object file, errors will occur. When this error occurs, the executable is not
generated. This could be due to incorrect function prototyping, an incorrect header file, or
other factors. If main() is written as Main(), a linked error will be generated.
5. Semantic Errors
When a sentence is syntactically correct but has no meaning, semantic errors occur. This is
similar to grammatical errors. If an expression is entered on the left side of the assignment
operator, a semantic error may occur.