Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views21 pages

Module1 Notes 2025 C

The document outlines the Problem Solving Life Cycle, which includes understanding, analyzing, developing, coding, and testing a solution to a problem. It introduces programming concepts such as algorithms, flowcharts, and programming methodologies like procedural and object-oriented programming. Additionally, it discusses the importance of modular programming and the use of pseudocode for planning and designing algorithms.

Uploaded by

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

Module1 Notes 2025 C

The document outlines the Problem Solving Life Cycle, which includes understanding, analyzing, developing, coding, and testing a solution to a problem. It introduces programming concepts such as algorithms, flowcharts, and programming methodologies like procedural and object-oriented programming. Additionally, it discusses the importance of modular programming and the use of pseudocode for planning and designing algorithms.

Uploaded by

dhruvalal771
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

1|Page

MODULE 1

Syllabus

1.1 Problem Solving Life Cycle – Understanding the Problem Statement, Analysing the problem,
Planning . Program design using Hierarchy charts, Topdown approach, Bottom-up approach.
Understanding basic Problem-Solving Tools: Algorithms: Definition & its attributes,
Flowchart: Definition & its attributes, symbols, Statements: Input-Output, DecisionMaking
&Looping, Module representation.
1.2 Introduction to Programming: Computer program. Classification of computer languages:
machine, assembly and high-level languages, Language translators (Assembler, Compiler,
Interpreter), Linker, Testing and debugging, 1.3 Types of errors- Syntax errors, Logical errors
and Runtime errors.

Problem Solving Life Cycle

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. In order to instruct a computer
correctly, the user must have clear understanding of the problem to be solved. Once the
problem is well defined and a method of solving it is developed, then instructing the
computer to solve the problem becomes relatively easier task. Thus, before attempt to write
a computer program to solve a given problem. It is necessary to formulate or define the
problem in a precise manner.

In order to solve a problem by the computer, one has to pass though certain stages or steps.
They are
1. Understanding the problem
2. Analyzing the problem
3. Developing the solution (Design)
4. Coding and implementation.

MAMS-YMBC Nimmy N Abraham BCA


2|Page

1.Understanding the problem:

Here we try to understand the problem to be solved in totally. Before going to the next stage
or step, we should be absolutely sure about the objectives of the given problem. In this phase,
we need to understand what is the problem statement, what is our requirement and what is
the output of the problem solution . Understanding the problem can be easily understood
with the help of following example: Calculate the average grade for all students in a class. You
need to know:

Total number of students in the class.


Individual grades of each student.
What are the unknown grades etc.

2. Analyzing the problem

After understanding thoroughly the problem to be solved, we look different ways of solving
the problem and evaluate each solution. The idea here is to search an appropriate solution
to the problem under consideration. Here, we determine the requirements like variables,
functions, etc. to solve the problem. It means that we gather the required resources to solve
the problem, which are defined in the first phase.The end result of this stage is a broad
overview of the sequence of operations that are to be carries out to solve the given problem.

3. Developing the solution (Design Phase):

During this phase, we develop a step by step procedure to solve the problem using the
specification given in the previous phase. This phase is very important for program
development. That means we write the solution in step by step statements. This is done with
the help of algorithm, pseudo code and flowcharts.

An algorithm is a precise sequence of instructions for solving a problem.


MAMS-YMBC Nimmy N Abraham BCA
3|Page

Example for Algorithm : Add two Numbers

1. Start
2. Input two numbers, say A and B
3. Add the two numbers → Sum = A + B
4. Display the result (Sum)
5. Stop

4. Coding and implementation:

This phase uses a programming language to write or implement the actual programming
instructions for the steps defined in the previous phase. In this phase, we construct the actual
program. That means we write the program to solve the given problem using programming
languages like C, C++, Java, etc. Writing a program is often called "writing code" or“implementing
an algorithm”. So the code (or source code) is actually the program itself.

Example

int main()
{
int A, B, Sum;
printf("Enter two numbers: ");
scanf("%d %d", &A, &B);
Sum = A + B;
printf("Sum = %d\n", Sum);
return 0;
}

MAMS-YMBC Nimmy N Abraham BCA


4|Page

After this phase, we check whether the code written in the previous step is solving the specified
problem or not. That means we test the program whether it is solving the problem for various
input data values or not. We also test whether it is providing the desired output or not. After that,
we check whether the code written in the previous step is solving the specified problem or not.
That means we test the program whether it is solving the problem for various input data values
or not. We also test whether it is providing the desired output or not.

Program design using Hierarchy charts/Types of Programming Methodologies

There are many types of programming methodologies prevalent among software developers, two
of the most common programming methodologies are as follows :

1. Procedural Programming
2. Object-oriented Programming

Procedural Programming : Problem is broken down into procedures, or blocks of code that
perform one task each. All procedures taken together form the whole program. It is suitable only
for small programs that have low level of complexity.

Example: For a calculator program that does addition, subtraction, multiplication, division,
square root and comparison, each of these operations can be developed as separate procedures.
In the main program each procedure would be invoked on the basis of user’s choice. This
methodology is suitable for solving small problems.

Object-oriented Programming : Here the solution revolves around entities or objects that are
part of problem. The solution deals with how to store data related to the entities, how the entities
behave and how they interact with each other. Example: If we have to develop a payroll
management system, we will have entities like employees, salary structure, leave rules, etc.
around which the solution must be built.

Software developers may choose one or a combination of more than one of these
methodologies to develop a software. Top-down and bottom-up approaches are two common
planning and program design strategies that can be used in a variety of contexts.

Top-down approach

MAMS-YMBC Nimmy N Abraham BCA


5|Page

A top-down approach (is also known as step-wise design) is essentially the breaking down of a
system to gain insight into its compositional sub-systems. In a top-down approach an overview of
the system is formulated, specifying but not detailing any first level subsystems. Each subsystem
is then refined in yet greater detail, sometimes in many additional subsystem levels, until the
entire specification is reduced to base elements. A top–down approach starts with the big picture,
then breaks down into smaller segments called modules. The top-down approach is mainly used
by Structured programming languages like C, Fortran, etc

Structure Charts: A structure chart, also called Hierarchy chart, show top-down design of
program. Each box in the structure chart indicates a task that program must accomplish. The Top
module, called the Main module or Control module.

For example

Advantages of top-down approach:

1. Using this approach, the problem solving process of big problem becomes easy.
2. This approach utilize the resources in a proper manner according to the project.

MAMS-YMBC Nimmy N Abraham BCA


6|Page

3. Testing and debugging is easier and efficient.


4. In this approach, project implementation is smoother and shorter.
5. This approach is good for detecting and correcting time delays.

Disadvantages of Top- Down approach

1. This approach is not suitable for solving highly complex problems.


2. This approach is less flexible (updation in the program) in comparison to bottom up approach.
Bottom-up Approach
In bottom-up approach, system design starts with the lowest level of components, which
are then interconnected to get higher level components. The bottom-up approach is used
by Object-Oriented programming languages like C++, C#, Java, etc.

Advantages of Bottom up Approach


1. Flexible: This approach is very flexible. Addition of new features and modification of features
is easier.
2. Reusability: As the parts of the program are created independent, therefore the possibility of
reusing them increases.
3. Reliability: This approach is more reliable, because in this case each part of the program is
independently created and tested first then it is integrated.
4. Lower Cost: In this approach the components are reused therefore the cost of the software
development decreases.

Disadvantages of Bottom Up Approach

1. It is difficult to evaluate the progress of the project in this approach.


2. The idea about the final product is obtained at end only.
MAMS-YMBC Nimmy N Abraham BCA
7|Page

Understanding basic Problem-Solving Tools:

In C programming, the basic problem-solving tools are the fundamental building blocks we use to
design and implement solutions. They include:

1. Algorithm:- An Algorithms represented in the form of a programming language is a program.


2. flowchart.
3. pseudocode

Algorithm : Algorithm is a very popular technique used to obtain solution for a given problem.
An Algorithm can be defined as a finite set of stepwise instructions that should be followed to
perform a specific task like solving a logical or a mathematical problem. An algorithm refers to the
logic of a program, it is a finite set of steps that provide a chain of actions for solving a problem.

An algorithm has following characteristics:


1. Input:-It receives an input.
2. Definiteness:-Each and every instruction should be precise and unambiguous i.e. each and
every instruction should be clear and should have only one meaning.
3. Uniqueness:- The results of each step is uniquely defined and depends only on the input and
results of the previous steps.
4. Finiteness:-One or more instructions should not be repeated infinitely. It means that the
algorithm must terminate after a finite number of instruction.
5. Output:-After the instructions are executed, the user should get the required results.

Example for Algorithm : Add two Numbers

1. Start
2. Input two numbers, say A and B
3. Add the two numbers → Sum = A + B
4. Display the result (Sum)
5. Stop

Flowcharts

MAMS-YMBC Nimmy N Abraham BCA


8|Page

Flowchart A flowchart is a pictorial representation of an algorithm. It’s a diagrammatic


representation of a problem-solving process(algorithm) in which steps are laid out in logical order
using geometrical symbols. It uses boxes of different shapes to denote different types of
instructions. Directed solid lines connecting these boxes indicate flow of operation- sequence in
which to execute the instruction. The process of drawing a flowchart for an algorithm is known
as flowcharting.

Flowchart Symbols and their usage

1. Terminal / Terminator:- An End or a Beginning

The terminator is used to show where your flow begins or ends. Ideally, you would
use words like 'Start', 'Begin', 'End

2. Process / Rectangle Flowchart Process object is used to illustrate a process, action


or an operation. These are represented by rectangles; and the text in the rectangle
mostly includes a verb

Num = 5

3. Data (Input/Output)

The Data object, often referred to as the I/O Shape shows the Inputs to and Outputs (Read and
Write) from a process. This takes the shape of a parallelogram.

Read A

MAMS-YMBC Nimmy N Abraham BCA


9|Page

4. Decision / Conditional

If a decision asks a question, the answer to the question determines which arrow you follow out
of the decision shape, it’s represented as a diamond (rhombus). These typically contain a Yes/No
question or True/False test. This symbol is unique in that it has two arrows coming out of it,
usually from the bottom point and right point, one corresponding to Yes or True, and one
corresponding to No or False.

5. Connection of different pages (Circle):

If the user needs to connect to another page or another section of the chart, and can’t
draw a line, the user can use a circle. The user draws the line to the circle and labels the
circle with a letter. Then place a copy of the circle where the user wants the flow to
continue.
6. Lines with Arrows:

A line or an arrow showing data flow that called “flow of control” in computer science.
An arrow coming from one symbol and ending at another symbol represents that control
passes to the symbol the arrow points to.

MAMS-YMBC Nimmy N Abraham BCA


10 | P a g e

Example for flow chart

Example 2: To check whether a number is positive or negative

Program Control Structures

Program Control Structures are the ways to control the flow of execution of statements.
They decide which instructions execute, how many times, and in what order. There
are 3 main types:
MAMS-YMBC Nimmy N Abraham BCA
11 | P a g e

1. Sequence logic
2. Selection logic
3. looping logic
Sequence Logic: Instructions are executed one after another in order.

Example:

int a = 5, b = 7;
int sum = a + b;
printf("%d", sum);

2. Selection (Decision) Logic

 Used to make choices (true/false conditions).


 Types:
o if statement
o if...else statement
o nested if
o switch statement

3. looping logic

There are many programming problems in which the same sequence of statements needs to be
performed again and again for a definite or indefinite number of times.
MAMS-YMBC Nimmy N Abraham BCA
12 | P a g e

General rules for Flowchart

1. Start and End must be represented with ovals (terminators).


2. Flow direction should normally go top to bottom or left to right.
3. One entry, one exit for each process or decision block.
4. Arrows should clearly show the flow of control.
5. Avoid crossing lines; use connectors if necessary.
6. Keep it simple and easy to understand.

Limitations of Flowchart
1. Complex for large problems – If the problem is big, the flowchart becomes very large
and confusing.
2. Time-consuming – Drawing neat and detailed flowcharts takes more time compared to
writing pseudocode or program directly.
3. Difficult to modify – Any change in the logic may require redrawing the entire
flowchart.
4. Not suitable for detailed coding – Flowcharts show the overall logic but not the exact
syntax or programming details.
5. Space-consuming – For complex programs, flowcharts require a lot of space to
represent all steps.
6. Less useful for very simple problems – Writing a flowchart for a small logic (like adding
two numbers) may be unnecessary.

Pseudocode
Pseudocode is another program planning tool used for planning program logic. “Psuedo”
means imitation or false and “Code” refers to the instruction written in a programming
languages. So its an imitation of actual computer instruction. Pseudocode (which means fake
code, because its not really programming code) specifies the steps required to accomplish the
task.

• Pseudocode is a type of structured English that is used to specify an algorithm.

MAMS-YMBC Nimmy N Abraham BCA


13 | P a g e

• Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax
rules.

Pseudocode is a way to write a program’s logic in plain language (like English) without
worrying about the syntax of any programming language.

 It’s not real code, so the computer cannot execute it.


 It’s meant for humans to understand the steps before actual coding.
 Helps in planning, designing, and explaining algorithms.

Example:

Module Representation

In C programming, large problems are usually divided into modules (smaller parts) for
easier understanding, debugging, and reusability. This is called modular programming.

Modules in C are represented mainly using functions.

1. Main Module

 The entry point of every C program is the main() function.


 It controls the execution flow and can call other modules (functions).

2. Sub-Modules (Functions)

 Each subtask is written as a separate function.


 Functions can be:
o Library functions (e.g., printf(), scanf(), sqrt()).
o User-defined functions (functions created by the programmer).

1.3 Introduction to Programming

MAMS-YMBC Nimmy N Abraham BCA


14 | P a g e

A program is a set of instructions that tell the computer to do various things; sometimes the
instruction it has to perform depends on what happened when it performed a previous
instruction. Computer programming languages are used to communicate instructions to a
computer. They are based on certain syntactic and semantic rules, which define the meaning of
each of the programming language constructs. The description of a programming language is
usually split into the two components of syntax (form) and semantics (meaning).

Classification of computer languages Programming languages are used for simulating real world
problems on computers. Computer languages are classified into three types.

Low-Level Language (Machine Language)


Low-Level language is the only language which can be understood by the computer. Binary
Language is an example of a low-level language. Low-level language is also known as Machine
Language. The binary language contains only two symbols 1 & 0. All the instructions of binary
language are written in the form of binary numbers 1's & 0's. A computer can directly understand
the binary language. Machine language is also known as the Machine Code.

As the CPU directly understands the binary language instructions, it does not require any
translator. CPU directly starts executing the binary language instructions and takes very less time

MAMS-YMBC Nimmy N Abraham BCA


15 | P a g e

to execute the instructions as it does not require any translation. Low-level language is considered
as the First Generation Language (1GL).

Advantage

 Can be executed very fast

Limitations

 Machine Dependent  Difficult to program  Error prone  Difficult to modify

Middle-Level Language (Assembly Language)


Middle-level language is a computer language in which the instructions are created using symbols
such as letters, digits and special characters. Assembly language is an example of middle-level
language. In assembly language, we use predefined words called mnemonics. Binary code
instructions in low-level language are replaced with mnemonics and operands in middle-level
language. But the computer cannot understand mnemonics, so we use a translator
called Assembler to translate mnemonics into binary language.

Assembler is a translator which takes assembly code as input and produces machine code as
output. That means, the computer cannot understand middle-level language, so it needs to be
translated into a low-level language to make it understandable by the computer. Assembler is
used to translate middle-level language into low-level language.

Advantages

 Writing instructions in a middle-level language is easier than writing instructions in a low-


level language.
 Middle-level language is more readable compared to low-level language.
 Easy to understand, find errors and modify.

Disadvantages

 Low-level language instructions are very difficult to use and understand.


 Low-level language instructions are machine-dependent, that means a program written
for a particular machine does not execute on another machine.
 In low-level language, there is more chance for errors and it is very difficult to find errors,
debug and modify.

MAMS-YMBC Nimmy N Abraham BCA


16 | P a g e

High-Level Language
A high-level language is a computer language which can be understood by the users. The high-
level language is very similar to human languages and has a set of grammar rules that are used
to make instructions more easily. Every high-level language has a set of predefined words known
as Keywords and a set of rules known as Syntax to create instructions. The high-level language is
easier to understand for the users but the computer can not understand it. High-level language
needs to be converted into the low-level language to make it understandable by the computer.
We use Compiler or interpreter to convert high-level language to low-level language.

Languages like COBOL, FORTRAN, BASIC, C, C++, JAVA, etc., are examples of high-level languages.
All these programming languages use human-understandable language like English to write
program instructions. These instructions are converted to low-level language by the compiler so
that it can be understood by the computer.

Advantages

 Writing instructions in a high-level language is easier.


 A high-level language is more readable and understandable.
 The programs created using high-level language runs on different machines with little
change or no change.
 Easy to understand, create programs, find errors and modify.

Disadvantages

 High-level language needs to be translated into low-level language.


 High-level language executes slower compared to middle and low-level languages.

Language translators
The computer doesn’t understand any language other than “Binary Language.” It becomes
necessary to process a HLL program me so as to make it understandable to the computer. The
system program which performs the above job is called language processors .

A translator or programming language processor is a computer program that performs the


translation of a program written in a given programming language into a functionally equivalent
program in another computer language (the target language), without losing the functional or
logical structure of the original code (the "essence" of each program). The code in a source file
stored on the disk must be translated into machine language. This is the job of the translator.
Assembler, Interpreter and Compliers are some of the language processors.
MAMS-YMBC Nimmy N Abraham BCA
17 | P a g e

1. Compiler
The language processor that reads the complete source program written in high-level language
as a whole in one go and translates it into an equivalent program in machine language is called
a Compiler. Example: C, C++, C#.

In a compiler, the source code is translated to object code successfully if it is free of


errors. The compiler specifies the errors at the end of the compilation with line numbers when
there are any errors in the source code. The errors must be removed before the compiler can
successfully recompile the source code again the object program can be executed number of
times without translating it again.

2. Assembler
The Assembler is used to translate the program written in Assembly language into machine
code. The source program is an input of an assembler that contains assembly language
instructions. The output generated by the assembler is the object code or machine code
understandable by the computer. Assembler is basically the 1st interface that is able to
communicate humans with the machine. We need an assembler to fill the gap between human
and machine so that they can communicate with each other. code written in assembly language
is some sort of mnemonics(instructions) like ADD, MUL, MUX, SUB, DIV, MOV and so on. and
the assembler is basically able to convert these mnemonics in binary code. Here, these
mnemonics also depend upon the architecture of the machine.

MAMS-YMBC Nimmy N Abraham BCA


18 | P a g e

3. Interpreter
The translation of a single statement of the source program into machine code is done by a
language processor and executes immediately before moving on to the next line is called an
interpreter. If there is an error in the statement, the interpreter terminates its translating
process at that statement and displays an error message. The interpreter moves on to the next
line for execution only after the removal of the error. An Interpreter directly executes
instructions written in a programming or scripting language without previously converting
them to an object code or machine code. An interpreter translates one line at a time and then
executes it.
Example: Perl, Python and Matlab.

Linker

A linker is a program that combines multiple object files generated by the assembler into a
single executable file. It resolves references between files and libraries, ensuring that all the
necessary code and data are linked together to form a complete program. For example, if a
program consists of multiple source files and external libraries, the linker combines them into a
single executable file ready for execution.

A linker in C is the tool that combines your program’s object files with library code (like printf,
scanf, sqrt, etc.) into a single executable.

Testing and Debugging

Testing is the process of checking whether the program works correctly and produces the
expected output. It ensures the program meets the requirements.

Debugging is the process of finding and fixing errors (bugs) in the program after testing detects
them.

MAMS-YMBC Nimmy N Abraham BCA


19 | P a g e

Types Of Errors

In any programming language errors are common. If we miss any syntax like parenthesis or
semicolon then we get syntax errors. Apart from this we also get run time errors during the
execution of code.
There are 5 types of error in C:
1. Syntax Errors
2. Runtime Errors
3. Logical Errors
4. Linked Errors
5. Semantic Errors

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.

#include <stdio.h>
int main()
{
// missing semicolon
printf("Hi!")
return 0;
}
Example 2: In this case, we are getting errors because of missing parenthesis before the output
statement and below the main(). This type of error is also called syntax error.
Run time Error

Run Time Error

In C programming, a runtime error is an error that occurs while the program is running, even
though the code compiled successfully.

Examples in C

Division by zero

int a = 5, b = 0;
int c = a / b;
MAMS-YMBC Nimmy N Abraham BCA
20 | P a g e

Logical Errors

logical error happens when a program runs without crashing but produces the wrong output
because the logic or steps used in the program are incorrect. In other words, the program is
syntactically correct (no compilation errors) but logically wrong (gives unexpected results).

If you want to calculate the average of 3 numbers, but you divide by 2 instead of 3.
The program will run, but the result is incorrect.

Linked Errors

A linker error occurs when the compiler has successfully compiled your program, but the linker
cannot combine all the parts into an executable file.

Multiple definitions

 You defined the same function or variable more than once.

int x = 10;
int x = 20; // ❌ linker error: multiple definition of `x`

Semantic Errors

A semantic error occurs when the syntax of the program is correct, and the program runs
without crashing, but the meaning of the code is incorrect.
Difference Between Logical and Semantic Errors

 Logical Error: Program runs but gives wrong output due to wrong logic.
MAMS-YMBC Nimmy N Abraham BCA
21 | P a g e

 Semantic Error: Program runs but behaves incorrectly because the meaning of the code
is wrong even though syntax is correct.

Examples

MAMS-YMBC Nimmy N Abraham BCA

You might also like